Tencent / rapidjson

A fast JSON parser/generator for C++ with both SAX/DOM style API
http://rapidjson.org/
Other
14.19k stars 3.53k forks source link

Regex validation for pattern is ignored or incorrect with this regex #2123

Open pasanbox opened 1 year ago

pasanbox commented 1 year ago

I'm using the same example from examples/schemavalidator.cpp.

My schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "title": "SampleMessage",
  "properties": {
    "id": {
      "type": "string"
    },
    "regexfield": {
      "type": "string",
      "pattern": "^[\\x00-\\x7F]*$"
    },
    "status": {
      "type": "string",
      "enum": [
        "VALID",
        "INVALID"
      ]
    }
  },
  "required": [
    "regexfield",
    "status"
  ]
}

My message;

{
  "id": "w10ooe",
  "regexfield": "w10ooe¼",
  "status": "VALID"
}

Expected result:

validation fail for pattern

Actual result

Input JSON is valid.

As you can see, the pattern is for validating if the regexfield contains only ASCII characters. However, the validation returns successful even when the field has a non-ascii value. The same regex gives expected result when checking with regex101.com.

smhdfdl commented 1 year ago

@pasanbox This comment might explain what you are seeing? https://github.com/Tencent/rapidjson/pull/1915#issuecomment-890048964