Skip to content

Commit

Permalink
Fix format regex escape sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanpenman committed Jul 21, 2022
1 parent 25dcdb1 commit 94d3bfd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/valijson/validation_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class ValidationVisitor: public constraints::ConstraintVisitor
}
} else if (format == "time") {
// Matches times like: 16:52:45Z, 16:52:45+02:00
std::regex time_regex("^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$");
std::regex time_regex("^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\\.[0-9]+)?(([Zz])|([\\+|\\-]([01][0-9]|2[0-3]):[0-5][0-9]))$");
if (std::regex_match(s, time_regex)) {
return true;
} else {
Expand All @@ -387,7 +387,7 @@ class ValidationVisitor: public constraints::ConstraintVisitor
}
} else if (format == "date-time") {
// Matches data times like: 2022-07-18T16:52:45Z, 2022-07-18T16:52:45+02:00
std::regex datetime_regex("^([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$");
std::regex datetime_regex("^([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\\.[0-9]+)?(([Zz])|([\\+|\\-]([01][0-9]|2[0-3]):[0-5][0-9]))$");
std::smatch matches;
if (std::regex_match(s, matches, datetime_regex)) {
const auto month = std::stoi(matches[2].str());
Expand Down

0 comments on commit 94d3bfd

Please sign in to comment.