diff options
author | Luke Kanies <luke@madstop.com> | 2009-09-03 17:22:08 -0700 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-09-04 11:58:31 +1000 |
commit | 19815dd32891eb182a3ad4d5937ba6ec9eda1261 (patch) | |
tree | 8d63d32c4fb41e22d99e36cc2f8b2aadff54316f /lib | |
parent | ea5847875b5fd7e2d13470d9e74bb0f671ee4d95 (diff) | |
download | puppet-19815dd32891eb182a3ad4d5937ba6ec9eda1261.tar.gz puppet-19815dd32891eb182a3ad4d5937ba6ec9eda1261.tar.xz puppet-19815dd32891eb182a3ad4d5937ba6ec9eda1261.zip |
Fixing #2592 - you can escape slashes in regexes
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/parser/lexer.rb | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb index 56863a2fc..e027a69d1 100644 --- a/lib/puppet/parser/lexer.rb +++ b/lib/puppet/parser/lexer.rb @@ -171,9 +171,14 @@ class Puppet::Parser::Lexer [self,value] end - TOKENS.add_token :REGEX, %r{/(.*?)/} do |lexer, value| - value.sub!(/^\/(.*?)\/$/,"\\1") - [self, Regexp.new(value)] + TOKENS.add_token :REGEX, %r{/[^/]*/} do |lexer, value| + # Make sure we haven't matched an escaped / + while value[-2..-2] == '\\' + other = lexer.scan_until(%r{/}) + value += other + end + regex = value.sub(%r{\A/}, "").sub(%r{/\Z}, '').gsub("\\/", "/") + [self, Regexp.new(regex)] end TOKENS.add_token :RETURN, "\n", :skip => true, :incr_line => true, :skip_text => true @@ -472,6 +477,12 @@ class Puppet::Parser::Lexer @scanner.skip(@skip) end + # Provide some limited access to the scanner, for those + # tokens that need it. + def scan_until(regex) + @scanner.scan_until(regex) + end + # we've encountered an opening quote... # slurp in the rest of the string and return it def slurpstring(quote) |