Commit ff4925b8 authored by Yukihiro Matsumoto's avatar Yukihiro Matsumoto

corrupted String#inspect on backslash escapes

parent 5937c292
...@@ -2943,18 +2943,15 @@ mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2) ...@@ -2943,18 +2943,15 @@ mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2)
mrb_value mrb_value
mrb_str_inspect(mrb_state *mrb, mrb_value str) mrb_str_inspect(mrb_state *mrb, mrb_value str)
{ {
const char *p, *pend, *prev; const char *p, *pend;
char buf[CHAR_ESC_LEN + 1]; char buf[CHAR_ESC_LEN + 1];
mrb_value result = mrb_str_new_cstr(mrb, "\""); mrb_value result = mrb_str_new_cstr(mrb, "\"");
p = RSTRING_PTR(str); pend = RSTRING_END(str); p = RSTRING_PTR(str); pend = RSTRING_END(str);
prev = p;
for (;p < pend; p++) { for (;p < pend; p++) {
unsigned int c, cc; unsigned int c, cc;
int n;
c = *p; c = *p;
n = 1;
if (c == '"'|| c == '\\' || (c == '#' && IS_EVSTR(p, pend))) { if (c == '"'|| c == '\\' || (c == '#' && IS_EVSTR(p, pend))) {
buf[0] = '\\'; buf[1] = c; buf[0] = '\\'; buf[1] = c;
mrb_str_buf_cat(mrb, result, buf, 2); mrb_str_buf_cat(mrb, result, buf, 2);
...@@ -2977,18 +2974,14 @@ mrb_str_inspect(mrb_state *mrb, mrb_value str) ...@@ -2977,18 +2974,14 @@ mrb_str_inspect(mrb_state *mrb, mrb_value str)
default: cc = 0; break; default: cc = 0; break;
} }
if (cc) { if (cc) {
if (p - n > prev) mrb_str_buf_cat(mrb, result, prev, p - n - prev);
buf[0] = '\\'; buf[0] = '\\';
buf[1] = (char)cc; buf[1] = (char)cc;
mrb_str_buf_cat(mrb, result, buf, 2); mrb_str_buf_cat(mrb, result, buf, 2);
prev = p;
continue; continue;
} }
else { else {
if (p - n > prev) mrb_str_buf_cat(mrb, result, prev, p - n - prev);
sprintf(buf, "\\%03o", c & 0377); sprintf(buf, "\\%03o", c & 0377);
mrb_str_buf_cat(mrb, result, buf, strlen(buf)); mrb_str_buf_cat(mrb, result, buf, strlen(buf));
prev = p;
continue; continue;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment