Skip to content

Commit eafb7dc

Browse files
committed
Stop rewriting \A to literal A in regexes
I introduced this behavior in: #12 but thinking about it again, it seems more annoying than it is helpful. If someone writes `\A` in their regex, they're probably writing it in Ruby with the expectation that it's beginning-of-string. It seems less likely that they're writing an ECMA 262 regex with the expectation that it matches a literal `A` (because why would they write it `\A`?).
1 parent 30ead71 commit eafb7dc

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

lib/json_schemer/schema/base.rb

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ def merge(
2525

2626
RUBY_REGEX_TYPES_TO_ECMA_262 = {
2727
:anchor => {
28-
:bos => 'A',
29-
:eos => 'z',
3028
:bol => '\A',
3129
:eol => '\z'
3230
},

test/json_schemer_test.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -904,10 +904,10 @@ def test_it_handles_regex_anchors
904904
refute(schema.valid?("foo\nfoo\nfoo"))
905905

906906
schema = JSONSchemer.schema({ 'pattern' => '\Afoo\z' })
907-
assert(schema.valid?('Afooz'))
908-
refute(schema.valid?('foo'))
909-
refute(schema.valid?('Afoo'))
910-
refute(schema.valid?('fooz'))
907+
assert(schema.valid?('foo'))
908+
refute(schema.valid?(' foo'))
909+
refute(schema.valid?('foo '))
910+
refute(schema.valid?("foo\nfoo\nfoo"))
911911
end
912912

913913
def test_it_handles_regexp_resolver

0 commit comments

Comments
 (0)