summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2021-02-09 13:50:36 -0800
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-02-20 11:17:47 +0900
commitcfd162d535c7a4f8b1f95255cc6be696a8b75557 (patch)
tree386d466aab972781cc6d1e35abd035bea506b65d /string.c
parentefd19badf43f4f1f24d5aec8a28e94a6e1e47b5b (diff)
Make String#{strip,lstrip}{,!} strip leading NUL bytes
The documentation already specifies that they strip whitespace and defines whitespace to include null. This wraps the new behavior in the appropriate guards in the specs, but does not specify behavior for previous versions, because this is a bug that could be backported. Fixes [Bug #17467]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4164
Diffstat (limited to 'string.c')
-rw-r--r--string.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/string.c b/string.c
index dbff149840..7605c225b9 100644
--- a/string.c
+++ b/string.c
@@ -9263,14 +9263,14 @@ lstrip_offset(VALUE str, const char *s, const char *e, rb_encoding *enc)
/* remove spaces at head */
if (single_byte_optimizable(str)) {
- while (s < e && ascii_isspace(*s)) s++;
+ while (s < e && (*s == '\0' || ascii_isspace(*s))) s++;
}
else {
while (s < e) {
int n;
unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc);
- if (!rb_isspace(cc)) break;
+ if (cc && !rb_isspace(cc)) break;
s += n;
}
}