Skip to content

Commit

Permalink
Fix exception when parsing invalid version
Browse files Browse the repository at this point in the history
  • Loading branch information
deepbluev7 committed Feb 22, 2022
1 parent 9be1d36 commit a4b55e8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions lib/structs/responses/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include <nlohmann/json.hpp>

const static std::regex VERSION_REGEX("r(\\d+)\\.(\\d+)\\.(\\d+)");

namespace mtx {
namespace responses {

Expand All @@ -15,7 +13,7 @@ from_json(const nlohmann::json &obj, Versions &response)
response.versions = obj.at("versions").get<std::vector<std::string>>();

for (auto &version : response.versions) {
if (!std::regex_match(version, VERSION_REGEX))
if (version.empty())
throw std::invalid_argument(version + ": invalid version");
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/responses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ TEST(Responses, Versions)

json error_data = R"({
"versions" : [
"r.0.0.1"
""
]
})"_json;

Expand Down

0 comments on commit a4b55e8

Please sign in to comment.