mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
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]
This commit is contained in:
parent
efd19badf4
commit
cfd162d535
Notes:
git
2021-02-20 11:18:14 +09:00
4 changed files with 40 additions and 20 deletions
4
string.c
4
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue