Skip to content

Commit

Permalink
Fix exception when parsing copyright with trailing semicolon
Browse files Browse the repository at this point in the history
  • Loading branch information
azrogers committed Feb 7, 2025
1 parent c9c45d9 commit c75dc53
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CesiumGltfContent/src/GltfUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
38 changes: 38 additions & 0 deletions CesiumGltfContent/test/TestGltfUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string_view> 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<std::string_view> 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<std::string_view> result =
GltfUtilities::parseGltfCopyright(model);

REQUIRE(result.size() == 4);
CHECK(result[0] == "Test");
CHECK(result[1] == "a");
CHECK(result[2] == "b");
CHECK(result[3] == "c");
}
}

0 comments on commit c75dc53

Please sign in to comment.