summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-24 14:01:41 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-24 14:01:41 +0000
commit00e9e27b69c7af6fab649c789c6698d256982046 (patch)
tree5b2749704e49b60f05b2cda2ad3bb7ff48f680d4
parentad50e0edb93af94463219b998bfacf7ecdb5c213 (diff)
* string.c (rb_str_rstrip_bang): raise exception when the encoding of
the string is dummy. * string.c (rb_str_rstrip_bang): remove nul characters even if the encoding of the string is not single byte optimizable. fixed [ruby-core:18844], reported by Michael Selig. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19529 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog11
-rw-r--r--string.c8
2 files changed, 16 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index e6ff9bc07a..d9255584ca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,15 @@
+Wed Sep 24 22:58:18 2008 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * string.c (rb_str_rstrip_bang): raise exception when the encoding of
+ the string is dummy.
+
+ * string.c (rb_str_rstrip_bang): remove nul characters even if the
+ encoding of the string is not single byte optimizable.
+ fixed [ruby-core:18844], reported by Michael Selig.
+
Wed Sep 24 19:01:45 2008 NAKAMURA Usaku <usa@ruby-lang.org>
- * string.c (rb_str_strip_bang): workaround for VC++8 x64.
+ * string.c (rb_str_rstrip_bang): workaround for VC++8 x64.
Wed Sep 24 17:44:44 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
diff --git a/string.c b/string.c
index a474856808..990694f24f 100644
--- a/string.c
+++ b/string.c
@@ -5856,19 +5856,23 @@ rb_str_rstrip_bang(VALUE str)
char *s, *t, *e;
enc = STR_ENC_GET(str);
+ if (rb_enc_dummy_p(enc)) {
+ rb_raise(rb_eEncCompatError, "incompatible encoding with this operation: %s", rb_enc_name(enc));
+ }
s = RSTRING_PTR(str);
if (!s || RSTRING_LEN(str) == 0) return Qnil;
t = e = RSTRING_END(str);
+ /* remove trailing spaces or '\0's */
if (single_byte_optimizable(str)) {
- /* remove trailing spaces or '\0's */
while (s < t && (*(t-1) == '\0' || rb_enc_isspace(*(t-1), enc))) t--;
}
else {
char *tp;
while ((tp = rb_enc_prev_char(s, t, e, enc)) != NULL) {
- if (!rb_enc_isspace(rb_enc_codepoint(tp, e, enc), enc)) break;
+ unsigned int c = rb_enc_codepoint(tp, e, enc);
+ if (c && !rb_enc_isspace(c, enc)) break;
t = tp;
}
}