Skip to content

Commit

Permalink
bugfix: allow #, ", and ' to be escaped by a backslash.
Browse files Browse the repository at this point in the history
  • Loading branch information
agentzh committed Apr 5, 2016
1 parent 767c0fa commit 7eca2ad
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/sregex/sre_yyparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2641,6 +2641,13 @@ yylex(YYSTYPE *lvalp, YYLTYPE *locp, sre_pool_t *pool, sre_char **src)
locp->last = *src;
return SRE_REGEX_TOKEN_CHAR;

case '"':
case '\'':
case '#':
lvalp->ch = c;
locp->last = *src;
return SRE_REGEX_TOKEN_CHAR;

default:
break;
}
Expand Down Expand Up @@ -2918,6 +2925,11 @@ yylex(YYSTYPE *lvalp, YYLTYPE *locp, sre_pool_t *pool, sre_char **src)
locp->last = *src;
return SRE_REGEX_TOKEN_BAD;

case '"':
case '\'':
case '#':
goto process_char;

default:
break;
}
Expand Down
12 changes: 12 additions & 0 deletions src/sregex/sre_yyparser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,13 @@ yylex(YYSTYPE *lvalp, YYLTYPE *locp, sre_pool_t *pool, sre_char **src)
locp->last = *src;
return SRE_REGEX_TOKEN_CHAR;

case '"':
case '\'':
case '#':
lvalp->ch = c;
locp->last = *src;
return SRE_REGEX_TOKEN_CHAR;

default:
break;
}
Expand Down Expand Up @@ -1327,6 +1334,11 @@ yylex(YYSTYPE *lvalp, YYLTYPE *locp, sre_pool_t *pool, sre_char **src)
locp->last = *src;
return SRE_REGEX_TOKEN_BAD;

case '"':
case '\'':
case '#':
goto process_char;

default:
break;
}
Expand Down
29 changes: 29 additions & 0 deletions t/01-sanity-06.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# vim:set ft= ts=4 sw=4 et fdm=marker:

use t::SRegex 'no_plan';

run_tests();

__DATA__

=== TEST 1: \&
--- re: a\&b
--- s eval: 'a&b'



=== TEST 2: [\&]
--- re: a[\&]b
--- s eval: 'a&b'



=== TEST 3: \# \" \'
--- re: a\#\"\'b
--- s eval: 'a#"\'b'



=== TEST 4: [\#\"\']
--- re: [a\#\"\'b]{4}
--- s eval: 'a#"\'b'
12 changes: 12 additions & 0 deletions t/01-sanity.t_
Original file line number Diff line number Diff line change
Expand Up @@ -1566,3 +1566,15 @@ re1 and re2 are wrong here.
=== TEST 252: [\&]
--- re: a[\&]b
--- s eval: 'a&b'



=== TEST 253: \# \" \'
--- re: a\#\"\'b
--- s eval: 'a#"\'b'



=== TEST 254: [\#\"\']
--- re: [a\#\"\'b]{4}
--- s eval: 'a#"\'b'

0 comments on commit 7eca2ad

Please sign in to comment.