Project

General

Profile

Feature #3575

String#split is inconsistent with empty string and negative limit

Added by Conrad.Irwin (Conrad Irwin) over 9 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:31296]

Description

=begin
I expect: "".split(",", -1) == [""]
Currently: "".split(",", -1) == []

According to the documentation, blank fields should not be stripped when a negative offset is provided.
=end


Related issues

Related to Ruby master - Feature #4335: String#split for empty string is always empty arrayRejected01/28/2011Actions
Related to Ruby master - Feature #5120: String#split needs to be logicalRejectedActions

Associated revisions

Revision e5c418d9
Added by drbrain (Eric Hodel) over 7 years ago

  • string.c (rb_str_split_m): Documented behavior of split on the empty string. [ruby-trunk - Feature #3575]

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

Revision 35275
Added by drbrain (Eric Hodel) over 7 years ago

  • string.c (rb_str_split_m): Documented behavior of split on the empty string. [ruby-trunk - Feature #3575]

Revision 35275
Added by drbrain (Eric Hodel) over 7 years ago

  • string.c (rb_str_split_m): Documented behavior of split on the empty string. [ruby-trunk - Feature #3575]

Revision 35275
Added by drbrain (Eric Hodel) over 7 years ago

  • string.c (rb_str_split_m): Documented behavior of split on the empty string. [ruby-trunk - Feature #3575]

Revision 35275
Added by drbrain (Eric Hodel) over 7 years ago

  • string.c (rb_str_split_m): Documented behavior of split on the empty string. [ruby-trunk - Feature #3575]

Revision 35275
Added by drbrain (Eric Hodel) over 7 years ago

  • string.c (rb_str_split_m): Documented behavior of split on the empty string. [ruby-trunk - Feature #3575]

Revision 35275
Added by drbrain (Eric Hodel) over 7 years ago

  • string.c (rb_str_split_m): Documented behavior of split on the empty string. [ruby-trunk - Feature #3575]

History

Updated by akr (Akira Tanaka) over 7 years ago

  • Description updated (diff)

I think Ruby thinks "" has no fields, not one field which have empty string.

So, "".split(",", -1) should return [].

Documentation issue, maybe.

Updated by drbrain (Eric Hodel) over 7 years ago

  • Category changed from core to doc
  • Assignee set to drbrain (Eric Hodel)

I will add a note to the documentation to cover the behavior of empty strings.

Updated by mame (Yusuke Endoh) over 7 years ago

  • Status changed from Open to Assigned
#4

Updated by drbrain (Eric Hodel) over 7 years ago

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

This issue was solved with changeset r35275.
Conrad, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • string.c (rb_str_split_m): Documented behavior of split on the empty string. [ruby-trunk - Feature #3575]

Also available in: Atom PDF