Skip to content

Regex metacharacters ('\d') not validated correctly in generated code #12

@explore-it

Description

@explore-it

Validation does not happen as expected when the input AsyncApi spec have metacharacter '\d' in a pattern to match digits 0 to 9.
Issue seems to be because '\d' is not escaped correctly in the regex pattern string inside generated Validate() and hence considers it as character 'd' instead of digit.

Example:
Input AsyncApi spec have pattern: ^(?:(\d{4}-[0-1][0-9]-[0-3][0-9]))$
Generated Validate() is below and it does not validate as expected,
void testasyncapi::schema::Date::Validate(const std::string& testValue)
{
std::regex regexPattern("^(?:(\d{4}-[0-1][0-9]-[0-3][0-9]))$");
std::smatch regexMatch;
std::regex_match(testValue, regexMatch, regexPattern);
if (regexMatch.empty()) throw ::JsonSchemaException("The string value did not match the required regular expression pattern '^(?:(\d{4}-[0-1][0-9]-[0-3][0-9]))$'");
}
Note: Tested only for metacharacter '\d'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions