From 94d3bfd39ad4dca1be0f700b5eea8e4234d0e7e8 Mon Sep 17 00:00:00 2001 From: Tristan Penman Date: Thu, 21 Jul 2022 22:45:25 +1000 Subject: [PATCH] Fix format regex escape sequences --- include/valijson/validation_visitor.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/valijson/validation_visitor.hpp b/include/valijson/validation_visitor.hpp index 3adb0d1..152d101 100644 --- a/include/valijson/validation_visitor.hpp +++ b/include/valijson/validation_visitor.hpp @@ -375,7 +375,7 @@ public: } } 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 { @@ -387,7 +387,7 @@ public: } } 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());