Project

General

Profile

Bug #10476

String.strip remove characters different than pure whitespace

Added by yld (Yves Le Douaron) over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
ruby 2.1.3p242
[ruby-core:66081]

Description

The offical documentation (http://www.ruby-doc.org/core-2.1.4/String.html#method-i-strip) says:
strip → new_str

Returns a copy of str with leading and trailing whitespace removed.

But

[9] pry(main)> "#{0.chr}#{9.chr}#{10.chr}#{11.chr}#{12.chr}#{13.chr}#{32.chr}" 
=> "\x00\t\n\v\f\r " 
[10] pry(main)> "#{0.chr}#{9.chr}#{10.chr}#{11.chr}#{12.chr}#{13.chr}#{32.chr}".length
=> 7
[11] pry(main)> "#{0.chr}#{9.chr}#{10.chr}#{11.chr}#{12.chr}#{13.chr}#{32.chr}".strip
=> "" 
([4] pry(main)> (0..255).each { |char| puts "char #{char} stripped" if char.chr.strip.empty? }
char 0 stripped
char 9 stripped
char 10 stripped
char 11 stripped
char 12 stripped
char 13 stripped
char 32 stripped

Stripped characters are

  1. Null char (0)
  2. Horizontal Tab (9)
  3. Line Feed (10)
  4. Vertical Tab (11)
  5. Form Feed (12)
  6. Carriage Return (13)
  7. Space (32)

Files

bug-10476.patch (2.16 KB) bug-10476.patch Anonymous, 11/15/2014 06:51 PM

Associated revisions

Revision 6abaf764
Added by ayumin (Ayumu AIZAWA) over 4 years ago

  • string.c: improve docs for String#strip and variations. [ruby-core:66081][Bug #10476]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49135 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 49135
Added by ayumin (Ayumu AIZAWA) over 4 years ago

  • string.c: improve docs for String#strip and variations. [ruby-core:66081][Bug #10476]

Revision 49135
Added by ayumin (Ayumu AIZAWA) over 4 years ago

  • string.c: improve docs for String#strip and variations. [ruby-core:66081][Bug #10476]

Revision 49135
Added by ayumin (Ayumu AIZAWA) over 4 years ago

  • string.c: improve docs for String#strip and variations. [ruby-core:66081][Bug #10476]

Revision 49135
Added by ayumin (Ayumu AIZAWA) over 4 years ago

  • string.c: improve docs for String#strip and variations. [ruby-core:66081][Bug #10476]

Revision 49135
Added by ayumin (Ayumu AIZAWA) over 4 years ago

  • string.c: improve docs for String#strip and variations. [ruby-core:66081][Bug #10476]

History

Updated by yld (Yves Le Douaron) over 4 years ago

With the old 1.8.7 interpreter, the behaviour of strip was different:

1.8.7-head :010 > "#{0.chr}#{9.chr}#{10.chr}#{11.chr}#{12.chr}#{13.chr}#{32.chr}".strip
 => "\000" 
1.8.7-head :011 > "#{0.chr}#{9.chr}#{10.chr}#{11.chr}#{12.chr}#{13.chr}#{32.chr}.#{0.chr}".strip
 => "\000\t\n\v\f\r ."

The null character was stripped from the end of the string but not from the beginning...

Updated by nobu (Nobuyoshi Nakada) over 4 years ago

  • Status changed from Open to Rejected

As the example in the doc states, "whitespace" includes these characters.

Updated by yld (Yves Le Douaron) over 4 years ago

The example only includes 4 of these 7 characters, null, form feed and vertical tab are missing.

Maybe a documentation update could be usefull?

Updated by nobu (Nobuyoshi Nakada) over 4 years ago

  • Category changed from core to doc
  • Status changed from Rejected to Assigned
  • Assignee changed from ruby-core to zzak (Zachary Scott)

Yes, definitely.

Updated by Anonymous over 4 years ago

How about something like this?

Updated by yld (Yves Le Douaron) over 4 years ago

It looks perfect.

Updated by ayumin (Ayumu AIZAWA) over 4 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

Applied in changeset r49135.


  • string.c: improve docs for String#strip and variations. [ruby-core:66081][Bug #10476]

Also available in: Atom PDF