Skip to content

Commit 5b55d3b

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 7aca73d commit 5b55d3b

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/regex_test.rb

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

1111
schema = JSONSchemer.schema({ 'pattern' => '\Afoo\z' })
12-
assert(schema.valid?('Afooz'))
13-
refute(schema.valid?('foo'))
14-
refute(schema.valid?('Afoo'))
15-
refute(schema.valid?('fooz'))
12+
assert(schema.valid?('foo'))
13+
refute(schema.valid?(' foo'))
14+
refute(schema.valid?('foo '))
15+
refute(schema.valid?("foo\nfoo\nfoo"))
1616
end
1717

1818
def test_it_handles_regexp_resolver

0 commit comments

Comments
 (0)