Skip to content

Commit

Permalink
[Truffle] Fixed String.split(Regexp) without a limit.
Browse files Browse the repository at this point in the history
Prior to this change trailing empty fields weren't being suppressed.
  • Loading branch information
nirvdrum committed Feb 5, 2015
1 parent 9c794dc commit c804f97
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/string/split_tags.txt
Expand Up @@ -12,7 +12,6 @@ fails:String#split with String tries converting limit to an integer via to_int
fails:String#split with String returns subclass instances based on self
fails:String#split with String does not call constructor on created subclass instances
fails:String#split with String taints the resulting strings if self is tainted
fails:String#split with Regexp suppresses trailing empty fields when limit isn't given or 0
fails:String#split with Regexp defaults to $; when regexp isn't given or nil
fails:String#split with Regexp includes all captures in the result array
fails:String#split with Regexp does not include non-matching captures in the result array
Expand All @@ -24,4 +23,3 @@ fails:String#split with Regexp taints an empty string if self is tainted
fails:String#split with Regexp retains the encoding of the source string
fails:String#split with Regexp splits a string on each character for a multibyte encoding and empty split
fails:String#split with Regexp returns an ArgumentError if an invalid UTF-8 string is supplied
fails:String#split with Regexp doesn't taints the resulting strings if the Regexp is tainted
Expand Up @@ -324,6 +324,13 @@ public RubyString[] split(final RubyString string, final boolean useLimit, final
}
}

// Suppress trailing empty fields if not using a limit and the supplied limit isn't negative.
if (!useLimit && limit == 0) {
while (! strings.isEmpty() && (strings.get(strings.size() - 1).length() == 0)) {
strings.remove(strings.size() - 1);
}
}

return strings.toArray(new RubyString[strings.size()]);
}

Expand Down

0 comments on commit c804f97

Please sign in to comment.