js_regex 3.4.0 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/js_regex/converter/anchor_converter.rb +2 -3
- data/lib/js_regex/converter/base.rb +2 -2
- data/lib/js_regex/converter/escape_converter.rb +1 -1
- data/lib/js_regex/converter/literal_converter.rb +9 -23
- data/lib/js_regex/converter/meta_converter.rb +4 -1
- data/lib/js_regex/converter/set_converter.rb +2 -3
- data/lib/js_regex/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81bb3bc59a709d6bf1eb70daf3a80361352c8478c4cfc0d158c28edad617f0ab
|
4
|
+
data.tar.gz: 95518db3ac6952c03874d8d5e9025fa1adb5953412e27b27add6d14ceb6ad163
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d85e5fddd9c7ee0ba3abf241ccc6675edfd632b6258312f2c7f0202896f8e0fdcc45baacef18973023ba4fdbff31763a511e8308e0fb8eb4934c88a45db270a9
|
7
|
+
data.tar.gz: 4103cec0a7465483c61938692e898f5d3d0e738c3c61ecafc8fe06e97f9166738edccf3ebd78ba3dde769c172428df2988c699cb024df2072ecb16e0d98c5ffc
|
@@ -23,9 +23,8 @@ class JsRegex
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def pass_boundary_with_warning(boundary)
|
26
|
-
|
27
|
-
|
28
|
-
'so it might act differently than in Ruby.')
|
26
|
+
warn_of("The anchor '#{boundary}' at index #{expression.ts} "\
|
27
|
+
'only works at ASCII word boundaries in JavaScript.')
|
29
28
|
boundary
|
30
29
|
end
|
31
30
|
end
|
@@ -54,11 +54,11 @@ class JsRegex
|
|
54
54
|
def warn_of_unsupported_feature(description = nil)
|
55
55
|
description ||= "#{subtype} #{expression.type}".tr('_', ' ')
|
56
56
|
full_desc = "#{description} '#{expression}'"
|
57
|
-
|
57
|
+
warn_of("Dropped unsupported #{full_desc} at index #{expression.ts}")
|
58
58
|
drop
|
59
59
|
end
|
60
60
|
|
61
|
-
def
|
61
|
+
def warn_of(text)
|
62
62
|
context.warnings << text
|
63
63
|
end
|
64
64
|
|
@@ -15,42 +15,28 @@ class JsRegex
|
|
15
15
|
if data =~ ASTRAL_PLANE_CODEPOINT_PATTERN
|
16
16
|
convert_astral_data(data)
|
17
17
|
else
|
18
|
-
|
18
|
+
escape_incompatible_bmp_literals(data)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def convert_astral_data(data)
|
23
|
-
data.each_char.each_with_object(Node.new) do |
|
24
|
-
if
|
25
|
-
node <<
|
23
|
+
data.each_char.each_with_object(Node.new) do |char, node|
|
24
|
+
if char =~ ASTRAL_PLANE_CODEPOINT_PATTERN
|
25
|
+
node << surrogate_substitution_for(char)
|
26
26
|
else
|
27
|
-
node <<
|
27
|
+
node << escape_incompatible_bmp_literals(char)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
33
|
-
|
34
|
-
ensure_forward_slashes_are_escaped(data)
|
35
|
-
)
|
32
|
+
def escape_incompatible_bmp_literals(data)
|
33
|
+
data.gsub('/', '\\/').gsub(/[\f\n\r\t]/) { |lit| Regexp.escape(lit) }
|
36
34
|
end
|
37
35
|
|
38
36
|
private
|
39
37
|
|
40
|
-
def
|
41
|
-
|
42
|
-
high = ((base / 1024).floor + 55_296).to_s(16)
|
43
|
-
low = (base % 1024 + 56_320).to_s(16)
|
44
|
-
"(?:\\u#{high}\\u#{low})"
|
45
|
-
end
|
46
|
-
|
47
|
-
def ensure_forward_slashes_are_escaped(data)
|
48
|
-
# literal slashes would signify the pattern end in JsRegex#to_s
|
49
|
-
data.gsub(%r{\\?/}, '\\/')
|
50
|
-
end
|
51
|
-
|
52
|
-
def ensure_json_compatibility(data)
|
53
|
-
data.gsub(%r{\\?([\f\n\r\t])}) { Regexp.escape($1) }
|
38
|
+
def surrogate_substitution_for(char)
|
39
|
+
CharacterSet::Writer.write_surrogate_ranges([], [char.codepoints])
|
54
40
|
end
|
55
41
|
end
|
56
42
|
|
@@ -8,6 +8,9 @@ class JsRegex
|
|
8
8
|
# Template class implementation.
|
9
9
|
#
|
10
10
|
class MetaConverter < JsRegex::Converter::Base
|
11
|
+
DOT_EXPANSION = '(?:[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\n\uD800-\uDFFF])'
|
12
|
+
ML_DOT_EXPANSION = '(?:[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF])'
|
13
|
+
|
11
14
|
private
|
12
15
|
|
13
16
|
def convert_data
|
@@ -15,7 +18,7 @@ class JsRegex
|
|
15
18
|
when :alternation
|
16
19
|
convert_alternatives
|
17
20
|
when :dot
|
18
|
-
expression.multiline? ?
|
21
|
+
expression.multiline? ? ML_DOT_EXPANSION : DOT_EXPANSION
|
19
22
|
else
|
20
23
|
warn_of_unsupported_feature
|
21
24
|
end
|
@@ -62,9 +62,8 @@ class JsRegex
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def pass_through_with_escaping
|
65
|
-
expression.to_s(:base)
|
66
|
-
|
67
|
-
end
|
65
|
+
string = expression.to_s(:base)
|
66
|
+
LiteralConverter.escape_incompatible_bmp_literals(string)
|
68
67
|
end
|
69
68
|
end
|
70
69
|
end
|
data/lib/js_regex/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js_regex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janosch Müller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: character_set
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.6'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: regexp_property_values
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0
|
47
|
+
version: '1.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0
|
54
|
+
version: '1.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|