File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class Regular < RegexpBased
2121 # @see (see Mustermann::Pattern#initialize)
2222 def initialize ( string , check_anchors : true , **options )
2323 string = $1 if string . to_s =~ /\A \( \? \- mix\: (.*)\) \Z / && string . inspect == "/#$1/"
24+ string = string . inspect . gsub! ( /(?<!\\ )(?:\s |#.*(?:$|\/ [mix]))/ , '' ) if extended_regexp? ( string )
2425 @check_anchors = check_anchors
2526 super ( string , **options )
2627 end
@@ -40,6 +41,10 @@ def check_anchors(scanner)
4041 raise CompileError , "regular expression should not contain %s: %p" % [ illegal . to_s , @string ]
4142 end
4243
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?
4449 end
4550end
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22require 'support'
3+ require 'timeout'
34require 'mustermann/regular'
45
56describe Mustermann ::Regular do
3839 it { should match ( '/foo%2Fbar' ) . capturing foo : 'foo%2Fbar' }
3940 end
4041
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+
4157 describe :check_achnors do
4258 context 'raises on anchors' do
4359 example { expect { Mustermann ::Regular . new ( '^foo' ) } . to raise_error ( Mustermann ::CompileError ) }
You can’t perform that action at this time.
0 commit comments