diff --git a/CesiumGltfContent/src/GltfUtilities.cpp b/CesiumGltfContent/src/GltfUtilities.cpp index fb4aef5fa..2786720c4 100644 --- a/CesiumGltfContent/src/GltfUtilities.cpp +++ b/CesiumGltfContent/src/GltfUtilities.cpp @@ -297,7 +297,7 @@ GltfUtilities::parseGltfCopyright(const CesiumGltf::Model& gltf) { rtrim = copyright.find_last_not_of(" \t", end - 1); result.emplace_back(copyright.substr(ltrim, rtrim - ltrim + 1)); start = end + 1; - } while (end != std::string::npos); + } while (end < copyright.size() - 1); } } diff --git a/CesiumGltfContent/test/TestGltfUtilities.cpp b/CesiumGltfContent/test/TestGltfUtilities.cpp index 5536a588a..5f9554af4 100644 --- a/CesiumGltfContent/test/TestGltfUtilities.cpp +++ b/CesiumGltfContent/test/TestGltfUtilities.cpp @@ -711,3 +711,41 @@ TEST_CASE("GltfUtilities::collapseToSingleBuffer") { CHECK(m.bufferViews[2].byteLength == 100); } } + +TEST_CASE("GltfUtilities::parseGltfCopyright") { + SUBCASE("properly parses multiple copyright entries") { + Model model; + model.asset.copyright = "Test;a;b;c"; + std::vector result = + GltfUtilities::parseGltfCopyright(model); + + REQUIRE(result.size() == 4); + CHECK(result[0] == "Test"); + CHECK(result[1] == "a"); + CHECK(result[2] == "b"); + CHECK(result[3] == "c"); + } + + SUBCASE("properly parses a single copyright entry") { + Model model; + model.asset.copyright = "Test"; + std::vector result = + GltfUtilities::parseGltfCopyright(model); + + REQUIRE(result.size() == 1); + CHECK(result[0] == "Test"); + } + + SUBCASE("properly parses an entry with a trailing semicolon") { + Model model; + model.asset.copyright = "Test;a;b;c;"; + std::vector result = + GltfUtilities::parseGltfCopyright(model); + + REQUIRE(result.size() == 4); + CHECK(result[0] == "Test"); + CHECK(result[1] == "a"); + CHECK(result[2] == "b"); + CHECK(result[3] == "c"); + } +} \ No newline at end of file