Skip to content

Commit 3b502ec

Browse files
committed
Convert space/nonspace regex classes to ECMA 262
Fixes new test failures from: json-schema-org/JSON-Schema-Test-Suite#380 Ruby's `\s` and `\S` don't match the [ECMA 262 spec][0]. This expands them into a character class that does.
1 parent b9d40f2 commit 3b502ec

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/json_schemer/schema/base.rb

+12-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ def merge(
2323
NET_HTTP_REF_RESOLVER = proc { |uri| JSON.parse(Net::HTTP.get(uri)) }
2424
BOOLEANS = Set[true, false].freeze
2525

26-
RUBY_REGEX_ANCHORS_TO_ECMA_262 = {
27-
:bos => 'A',
28-
:eos => 'z',
29-
:bol => '\A',
30-
:eol => '\z'
26+
RUBY_REGEX_TYPES_TO_ECMA_262 = {
27+
:anchor => {
28+
:bos => 'A',
29+
:eos => 'z',
30+
:bol => '\A',
31+
:eol => '\z'
32+
},
33+
:type => {
34+
:space => '[\t\r\n\f\v\uFEFF\u2029\p{Zs}]',
35+
:nonspace => '[^\t\r\n\f\v\uFEFF\u2029\p{Zs}]'
36+
}
3137
}.freeze
3238

3339
INSERT_DEFAULT_PROPERTY = proc do |data, property, property_schema, _parent|
@@ -600,7 +606,7 @@ def ecma_262_regex(pattern)
600606
@ecma_262_regex ||= {}
601607
@ecma_262_regex[pattern] ||= Regexp.new(
602608
Regexp::Scanner.scan(pattern).map do |type, token, text|
603-
type == :anchor ? RUBY_REGEX_ANCHORS_TO_ECMA_262.fetch(token, text) : text
609+
RUBY_REGEX_TYPES_TO_ECMA_262.dig(type, token) || text
604610
end.join
605611
)
606612
end

0 commit comments

Comments
 (0)