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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76344824ca1ba10360b72c42fce4fe6b667dd01761665a9b36c4ab071bbaecba
4
- data.tar.gz: 37ceeda59137c6871be4d3782110d06c93e0f6be85c0332bad9a8afad0831d71
3
+ metadata.gz: 81bb3bc59a709d6bf1eb70daf3a80361352c8478c4cfc0d158c28edad617f0ab
4
+ data.tar.gz: 95518db3ac6952c03874d8d5e9025fa1adb5953412e27b27add6d14ceb6ad163
5
5
  SHA512:
6
- metadata.gz: 2199e2674f5187352a9e7a428266e4d35290630e4111c24c4f2f2514d2e64f46fc98512c62d5c97831c3719ca3dd90cccb7dabacb9285faa8c2d8087af94d2ea
7
- data.tar.gz: 235c68de51d6dc365f49354a5e79aa73f616ebd6e7386a7a596a3c09817a7a1b242a31024af3eae7206cf89395a8eadfce9c0819a14a62b56104a2c851850082
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
- warn("The boundary '#{boundary}' at index #{expression.ts} "\
27
- 'is not unicode-aware in JavaScript, '\
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
- warn("Dropped unsupported #{full_desc} at index #{expression.ts}")
57
+ warn_of("Dropped unsupported #{full_desc} at index #{expression.ts}")
58
58
  drop
59
59
  end
60
60
 
61
- def warn(text)
61
+ def warn_of(text)
62
62
  context.warnings << text
63
63
  end
64
64
 
@@ -44,7 +44,7 @@ class JsRegex
44
44
  when :control, :meta_sequence
45
45
  unicode_escape_codepoint
46
46
  when :literal
47
- LiteralConverter.convert_data(data)
47
+ LiteralConverter.convert_data(expression.char)
48
48
  when *ESCAPES_SHARED_BY_RUBY_AND_JS
49
49
  pass_through
50
50
  when :bell, :escape
@@ -15,42 +15,28 @@ class JsRegex
15
15
  if data =~ ASTRAL_PLANE_CODEPOINT_PATTERN
16
16
  convert_astral_data(data)
17
17
  else
18
- convert_bmp_data(data)
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 |chr, node|
24
- if chr =~ ASTRAL_PLANE_CODEPOINT_PATTERN
25
- node << surrogate_pair_for(chr)
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 << convert_bmp_data(chr)
27
+ node << escape_incompatible_bmp_literals(char)
28
28
  end
29
29
  end
30
30
  end
31
31
 
32
- def convert_bmp_data(data)
33
- ensure_json_compatibility(
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 surrogate_pair_for(astral_char)
41
- base = astral_char.codepoints.first - 65_536
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? ? '(?:.|\n)' : '.'
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).gsub(%r{([\f\n\r\t])|(/)}) do
66
- $1 ? Regexp.escape($1) : "\\#{$2}"
67
- end
65
+ string = expression.to_s(:base)
66
+ LiteralConverter.escape_incompatible_bmp_literals(string)
68
67
  end
69
68
  end
70
69
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class JsRegex
4
- VERSION = '3.4.0'
4
+ VERSION = '3.5.0'
5
5
  end
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.0
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-06-07 00:00:00.000000000 Z
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.5'
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.5'
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.3'
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.3'
54
+ version: '1.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement