Skip to content

Commit c804f97

Browse files
committed
[Truffle] Fixed String.split(Regexp) without a limit.
Prior to this change trailing empty fields weren't being suppressed.
1 parent 9c794dc commit c804f97

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

spec/truffle/tags/core/string/split_tags.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ fails:String#split with String tries converting limit to an integer via to_int
1212
fails:String#split with String returns subclass instances based on self
1313
fails:String#split with String does not call constructor on created subclass instances
1414
fails:String#split with String taints the resulting strings if self is tainted
15-
fails:String#split with Regexp suppresses trailing empty fields when limit isn't given or 0
1615
fails:String#split with Regexp defaults to $; when regexp isn't given or nil
1716
fails:String#split with Regexp includes all captures in the result array
1817
fails:String#split with Regexp does not include non-matching captures in the result array
@@ -24,4 +23,3 @@ fails:String#split with Regexp taints an empty string if self is tainted
2423
fails:String#split with Regexp retains the encoding of the source string
2524
fails:String#split with Regexp splits a string on each character for a multibyte encoding and empty split
2625
fails:String#split with Regexp returns an ArgumentError if an invalid UTF-8 string is supplied
27-
fails:String#split with Regexp doesn't taints the resulting strings if the Regexp is tainted

truffle/src/main/java/org/jruby/truffle/runtime/core/RubyRegexp.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,13 @@ public RubyString[] split(final RubyString string, final boolean useLimit, final
324324
}
325325
}
326326

327+
// Suppress trailing empty fields if not using a limit and the supplied limit isn't negative.
328+
if (!useLimit && limit == 0) {
329+
while (! strings.isEmpty() && (strings.get(strings.size() - 1).length() == 0)) {
330+
strings.remove(strings.size() - 1);
331+
}
332+
}
333+
327334
return strings.toArray(new RubyString[strings.size()]);
328335
}
329336

0 commit comments

Comments
 (0)