summaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-09 05:38:59 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-09 05:38:59 +0000
commit637b2d09478a512b1cd0d9fe8df716791d30f063 (patch)
treec2b417ada73e49e3385cf63650ff888dea112928 /string.c
parentd6b9e4324c257a789e2e5126d182384232bf9fb6 (diff)
downloadruby-637b2d09478a512b1cd0d9fe8df716791d30f063.tar.gz
ruby-637b2d09478a512b1cd0d9fe8df716791d30f063.tar.xz
ruby-637b2d09478a512b1cd0d9fe8df716791d30f063.zip
* string.c (rb_str_inspect): escape # which starts an expression
substitution. fixed: [ruby-core:03922] * string.c (rb_str_dump): not escape # which isn't a substitution. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@7519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/string.c b/string.c
index aac1f2bf6..464bb49c0 100644
--- a/string.c
+++ b/string.c
@@ -946,6 +946,8 @@ rb_str_equal(str1, str2)
return Qfalse;
}
+#define IS_EVSTR(p,e) ((p) < (e) && (*(p) == '$' || *(p) == '@' || *(p) == '{'))
+
/*
* call-seq:
* str.eql?(other) => true or false
@@ -2568,7 +2570,7 @@ rb_str_inspect(str)
rb_str_buf_cat(result, p - 1, len);
p += len - 1;
}
- else if (c == '"'|| c == '\\') {
+ else if (c == '"'|| c == '\\' || (c == '#' && IS_EVSTR(p, pend))) {
s[0] = '\\'; s[1] = c;
rb_str_buf_cat(result, s, 2);
}
@@ -2640,11 +2642,15 @@ rb_str_dump(str)
switch (c) {
case '"': case '\\':
case '\n': case '\r':
- case '\t': case '\f': case '#':
+ case '\t': case '\f':
case '\013': case '\007': case '\033':
len += 2;
break;
+ case '#':
+ len += IS_EVSTR(p, pend) ? 2 : 1;
+ break;
+
default:
if (ISPRINT(c)) {
len++;
@@ -2669,7 +2675,7 @@ rb_str_dump(str)
*q++ = c;
}
else if (c == '#') {
- *q++ = '\\';
+ if (IS_EVSTR(p, pend)) *q++ = '\\';
*q++ = '#';
}
else if (ISPRINT(c)) {