Skip to content

Commit

Permalink
[core] change Illegal escape sequence policy
Browse files Browse the repository at this point in the history
Previously: Silently ignore illegal escapes even for a-zA-Z
     and change the string from "foo\o" to "fooo"
Now: Throw "Illegal escape sequence \o in foo\o"
See GH #1103
  • Loading branch information
Reini Urban committed Oct 15, 2014
1 parent a918916 commit b51fb81
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/string/api.c
Expand Up @@ -2657,6 +2657,9 @@ Parrot_str_unescape_string(PARROT_INTERP, ARGIN(const STRING *src),
case 'f': next = '\f'; break;
case 'r': next = '\r'; break;
case 'e': next = '\x1B'; break;
/* and previously handled in the default case: */
case '\\': next = '\\'; break;
case '"': next = '"'; break;
/* Escape character */
case 'c':
if (itersrc.bytepos >= srclen) break;
Expand Down Expand Up @@ -2747,7 +2750,16 @@ Parrot_str_unescape_string(PARROT_INTERP, ARGIN(const STRING *src),
pending = 1;
break;
default:
next = c;
/* die with Illegal escape sequences but allow quoting of special chars */
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
/* next = c; for a deprecation cycle? */
/* catch inproper use of \O, \o */
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_CHARACTER,
"Illegal escape sequence \\%c in '%Ss'", c, src);
}
else {
next = c; /* ignore the \, like \[, \}, \' */
}
}
}
STRING_iter_set_and_advance(interp, result, &iterdest, next);
Expand All @@ -2773,6 +2785,10 @@ Unescapes the specified C string. These sequences are covered:
\Uhhhhhhhh 8 hex digits
\a, \b, \t, \n, \v, \f, \r, \e
These sequences are not escaped: C<\\ \" \' \?>
All other escape sequences within C<[a-zA-Z]> are illegal.
=cut
*/
Expand Down

0 comments on commit b51fb81

Please sign in to comment.