Skip to content

Commit 03be549

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 abda12c commit 03be549

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,17 +23,23 @@ 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
ECMA_262_REGEXP_RESOLVER = proc do |pattern|
3440
Regexp.new(
3541
Regexp::Scanner.scan(pattern).map do |type, token, text|
36-
type == :anchor ? RUBY_REGEX_ANCHORS_TO_ECMA_262.fetch(token, text) : text
42+
RUBY_REGEX_TYPES_TO_ECMA_262.dig(type, token) || text
3743
end.join
3844
)
3945
end

0 commit comments

Comments
 (0)