+22
-1
lines changedFilter options
+22
-1
lines changed Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ class Regular < RegexpBased
21
21
# @see (see Mustermann::Pattern#initialize)
22
22
def initialize(string, check_anchors: true, **options)
23
23
string = $1 if string.to_s =~ /\A\(\?\-mix\:(.*)\)\Z/ && string.inspect == "/#$1/"
24
+
string = string.inspect.gsub!(/(?<!\\)(?:\s|#.*(?:$|\/[mix]))/, '') if extended_regexp?(string)
24
25
@check_anchors = check_anchors
25
26
super(string, **options)
26
27
end
@@ -40,6 +41,10 @@ def check_anchors(scanner)
40
41
raise CompileError, "regular expression should not contain %s: %p" % [illegal.to_s, @string]
41
42
end
42
43
43
-
private :compile, :check_anchors
44
+
def extended_regexp?(string)
45
+
not (Regexp.new(string).options & Regexp::EXTENDED).zero?
46
+
end
47
+
48
+
private :compile, :check_anchors, :extended_regexp?
44
49
end
45
50
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
1
1
# frozen_string_literal: true
2
2
require 'support'
3
+
require 'timeout'
3
4
require 'mustermann/regular'
4
5
5
6
describe Mustermann::Regular do
@@ -38,6 +39,21 @@
38
39
it { should match('/foo%2Fbar') .capturing foo: 'foo%2Fbar' }
39
40
end
40
41
42
+
43
+
context 'with Regexp::EXTENDED' do
44
+
let(:pattern) {
45
+
%r{
46
+
\/compare\/ # match any URL beginning with \/compare\/
47
+
(.+) # extract the full path (including any directories)
48
+
\/ # match the final slash
49
+
([^.]+) # match the first SHA1
50
+
\.{2,3} # match .. or ...
51
+
(.+) # match the second SHA1
52
+
}x
53
+
}
54
+
example { expect { Timeout.timeout(1){ Mustermann::Regular.new(pattern) }}.not_to raise_error(Timeout::Error) }
55
+
end
56
+
41
57
describe :check_achnors do
42
58
context 'raises on anchors' do
43
59
example { expect { Mustermann::Regular.new('^foo') }.to raise_error(Mustermann::CompileError) }
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4