[wp-trac] [WordPress Trac] #44949: Add support for JSON Schema string pattern to REST API

WordPress Trac noreply at wordpress.org
Sun Sep 16 22:14:51 UTC 2018


#44949: Add support for JSON Schema string pattern to REST API
----------------------------------------+------------------------------
 Reporter:  jason_the_adams             |       Owner:  (none)
     Type:  enhancement                 |      Status:  new
 Priority:  normal                      |   Milestone:  Awaiting Review
Component:  REST API                    |     Version:  trunk
 Severity:  normal                      |  Resolution:
 Keywords:  has-patch needs-unit-tests  |     Focuses:
----------------------------------------+------------------------------

Comment (by TimothyBlynJacobs):

 My understanding is that the `[a-zA-Z]` part is the actual regex and for
 convenience purposes you can pass flags to the regex by using the
 delimiter syntax to instantiate the `RegExp`.

 Reference Implementations:
 - PHP: https://github.com/justinrainbow/json-
 schema/blob/master/src/JsonSchema/Constraints/StringConstraint.php#L43
 - PHP: https://github.com/swaggest/php-json-
 schema/blob/aa5ce4073adb69f36f84255392b69b3f6588d086/src/Helper.php#L15
 - PHP: https://github.com/opis/json-
 schema/blob/master/src/Validator.php#L1209
 - JS:
 https://github.com/epoberezkin/ajv/blob/master/lib/dot/pattern.jst#L8
 - JS: https://github.com/mafintosh/is-my-json-
 valid/blob/master/index.js#L128
 - Java: https://github.com/everit-org/json-
 schema/blob/master/core/src/main/java/org/everit/json/schema/regexp/JavaUtilRegexpFactory.java#L12
 ( You have to jump around a bunch, but it uses just the regex, adding
 flags is a separate method:
 https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#compile(java.lang.String)
 )

 > That said, I agree that it's the way to go. I don't think we'll need any
 flags added to the regex, do you?
 Interestingly, looking at the PHP validators, they all use the `u` flag.
 Presumably to reject non UTF-8 characters. I believe PHP requires JSON to
 be in UTF-8. To be consistent, we might also want to add this flag so it
 rejects non UTF-8 strings since request data might not come from JSON.

 > If necessary, the user can always add things via modifiers such as (?i).
 I don't think we should recommend this. The spec recommends schema authors
 to limit themselves to regular expressions that have the highest change of
 being interoperable: http://json-schema.org/latest/json-schema-
 validation.html#regexInterop

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44949#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list