Project

General

Profile

Actions

Bug #17467

closed

What makes strip() and lstrip() not stripping \u0000 from beginning of the string?

Added by SouravGoswami (Sourav Goswami) almost 4 years ago. Updated over 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
[ruby-core:101676]

Description

Both strip(), and rstrip() will delete \u0000 from the end of a string. But I have a string that has "\u0000hello\u0000".

Output from strip, lstrip and rstrip:

"\u0000hello\u0000".strip # => "\u0000hello"
"\u0000hello\u0000".lstrip # => "\u0000hello\u0000"
"\u0000hello\u0000".rstrip # => "\u0000hello"

Same goes for \x00 as well.

While it's quite ridiculous to have NULL at the beginning of the string, but what makes it not strip? Is that slow or is that because it's never used?

Actions #1

Updated by SouravGoswami (Sourav Goswami) almost 4 years ago

  • Subject changed from What makes strip() and lstrip() not stripping \u0000? to What makes strip() and lstrip() not stripping \u0000 from beginning of the string?

Updated by jeremyevans0 (Jeremy Evans) almost 4 years ago

I agree that this is a bug. The documentation for strip and lstrip specifies that the whitespace should be stripped, and defines whitespace to include null. I have submitted a pull request to fix it: https://github.com/ruby/ruby/pull/4164

Actions #3

Updated by jeremyevans (Jeremy Evans) almost 4 years ago

  • Status changed from Open to Closed

Applied in changeset git|cfd162d535c7a4f8b1f95255cc6be696a8b75557.


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]

Actions #4

Updated by znz (Kazuhiro NISHIYAMA) almost 4 years ago

Japanese reference manual mentions treatment "\0".
(for example: https://docs.ruby-lang.org/ja/latest/method/String/i/strip.html )

If this will backport to released versions, it affects version branching in Japanese reference manual.

Which versions will have backports?

I have no opinion to backport or not.
I only want to know how to mention changed version in Japanese reference manual.

Updated by byroot (Jean Boussier) over 3 years ago

I believe this fix should be backported.

Updated by jeremyevans0 (Jeremy Evans) over 3 years ago

  • Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN to 2.6: UNKNOWN, 2.7: REQUIRED, 3.0: REQUIRED

@byroot (Jean Boussier) I marked this for backporting. Here's the guide for how to do that: https://bugs.ruby-lang.org/projects/ruby/wiki/HowToRequestBackport

Updated by nagachika (Tomoyuki Chikanaga) over 3 years ago

  • Backport changed from 2.6: UNKNOWN, 2.7: REQUIRED, 3.0: REQUIRED to 2.6: UNKNOWN, 2.7: REQUIRED, 3.0: DONE

ruby_3_0 5af5ea7f860ed64062796e54e73274e7a56c7280 merged revision(s) cfd162d535c7a4f8b1f95255cc6be696a8b75557.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0