summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-21 05:09:17 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-21 05:09:17 +0000
commit05d1d29d1f4a87620371463d8c7942e170be031f (patch)
tree9c60e81b768cb81acff67a8b02a4d7d9d4d4aa5e /string.c
parent188d85934be95800b917a0e21e36484622eae610 (diff)
Don't allow mixed escape
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61381 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/string.c b/string.c
index 9b99c19ecc..2cb09f5372 100644
--- a/string.c
+++ b/string.c
@@ -6107,7 +6107,7 @@ unescape_ascii(unsigned int c)
}
static void
-undump_after_backslash(VALUE undumped, const char **ss, const char *s_end, rb_encoding **penc, bool *utf8)
+undump_after_backslash(VALUE undumped, const char **ss, const char *s_end, rb_encoding **penc, bool *utf8, bool *binary)
{
const char *s = *ss;
unsigned int c;
@@ -6136,6 +6136,9 @@ undump_after_backslash(VALUE undumped, const char **ss, const char *s_end, rb_en
s++;
break;
case 'u':
+ if (*binary) {
+ rb_raise(rb_eRuntimeError, "hex escape and Unicode escape are mixed");
+ }
*utf8 = true;
if (++s >= s_end) {
rb_raise(rb_eRuntimeError, "invalid Unicode escape");
@@ -6188,6 +6191,10 @@ undump_after_backslash(VALUE undumped, const char **ss, const char *s_end, rb_en
}
break;
case 'x':
+ if (*utf8) {
+ rb_raise(rb_eRuntimeError, "hex escape and Unicode escape are mixed");
+ }
+ *binary = true;
if (++s >= s_end) {
rb_raise(rb_eRuntimeError, "invalid hex escape");
}
@@ -6226,6 +6233,7 @@ str_undump(VALUE str)
rb_encoding *enc = rb_enc_get(str);
VALUE undumped = rb_enc_str_new(s, 0L, enc);
bool utf8 = false;
+ bool binary = false;
int w;
rb_must_asciicompat(str);
@@ -6296,7 +6304,7 @@ str_undump(VALUE str)
if (s >= s_end) {
rb_raise(rb_eRuntimeError, "invalid escape");
}
- undump_after_backslash(undumped, &s, s_end, &enc, &utf8);
+ undump_after_backslash(undumped, &s, s_end, &enc, &utf8, &binary);
}
else {
rb_str_cat(undumped, s++, 1);