Skip to content

Loading…

bugfix escape charactor for Regexp class #1038

Merged
merged 1 commit into from

1 participant

@ghost

escape character type would have been limited current mruby.
(Ex: '\ t' isn't escaped.)

Code and execution environment are as follows:

  • environment(add regexp gem to build_config.rb)
 # Use Regexp class
 conf.gem :git => 'git@github.com:masamitsu-murase/mruby-hs-regexp.git'
  • sample code(literal.rb):
p (/a\nb/ =~ "a\nb")     # => 0
p (/a
b/ =~ "a\nb")            # => 0
p (%r!a\tb! =~ "a\tb")   # => 0
p (/a\\tb/ =~ "a\\tb")   # => 0
  • ruby
$ ruby -v
ruby 1.9.3p385 (2013-02-06 revision 39114) [x86_64-linux]
$ ruby literal.rb
0 # => OK
0 # => OK
0 # => OK
0 # => OK
  • before(current mruby/mruby)
$ ./bin/mruby literal.rb
0 # => OK
0 # => OK
0 # => OK
nil # => NG
  • after(pr-regexp-escape)
$ ./bin/mruby literal.rb
0 # => OK
0 # => OK
0 # => OK
0 # => OK
@matz matz merged commit f6646f4 into mruby:master

1 check passed

Details default The Travis build passed
@ghost ghost deleted the unknown repository branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 21, 2013
  1. bugfix escape charactor for Regexp class

    Kouki Ooyatsu committed
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 11 deletions.
  1. +4 −11 src/parse.y
View
15 src/parse.y
@@ -3459,17 +3459,9 @@ read_escape(parser_state *p)
return c;
case 'b': /* backspace */
- if (is_strterm_type(p, STR_FUNC_REGEXP)) {
- tokadd(p, '\\');
- return 'b';
- }
return '\010';
case 's': /* space */
- if (is_strterm_type(p, STR_FUNC_REGEXP)) {
- tokadd(p, '\\');
- return 's';
- }
return ' ';
case 'M':
@@ -3507,9 +3499,6 @@ read_escape(parser_state *p)
return '\0';
default:
- if (is_strterm_type(p, STR_FUNC_REGEXP)) {
- tokadd(p, '\\');
- }
return c;
}
}
@@ -3583,6 +3572,10 @@ parse_string(parser_state *p)
}
else {
pushback(p, c);
+
+ if(type & STR_FUNC_REGEXP)
+ tokadd(p, '\\');
+
tokadd(p, read_escape(p));
if (hinf)
hinf->line_head = FALSE;
Something went wrong with that request. Please try again.