From 5af5ea7f860ed64062796e54e73274e7a56c7280 Mon Sep 17 00:00:00 2001 From: nagachika Date: Sun, 23 May 2021 16:09:17 +0900 Subject: merge revision(s) cfd162d535c7a4f8b1f95255cc6be696a8b75557: [Backport #17467] 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] --- spec/ruby/core/string/lstrip_spec.rb | 18 ++++++++++++------ spec/ruby/core/string/strip_spec.rb | 22 ++++++++++------------ string.c | 4 ++-- test/ruby/test_string.rb | 16 ++++++++++++++++ 4 files changed, 40 insertions(+), 20 deletions(-) --- string.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 82850577ff..c2919abeee 100644 --- a/string.c +++ b/string.c @@ -9265,14 +9265,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; } } -- cgit v1.2.3