Skip to content

Commit

Permalink
Switch from RubyArray addAll to concat method to preserve the encodin…
Browse files Browse the repository at this point in the history
…g and avoid implicit deconding in addAll iterator
  • Loading branch information
andsel committed Jan 28, 2025
1 parent 3a090a0 commit a84656e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,22 @@ public RubyArray extract(final ThreadContext context, IRubyObject data) {
final RubyArray entities = data.convertToString().split(delimiter, -1);
if (!bufferFullErrorNotified) {
input.clear();
input.addAll(entities);
input.concat(entities);
} else {
// after a full buffer signal
if (input.isEmpty()) {
// after a buffer full error, the remaining part of the line, till next delimiter,
// has to be consumed, unless the input buffer doesn't still contain fragments of
// subsequent tokens.
entities.shift(context);
input.addAll(entities);
input.concat(entities);
} else {
// merge last of the input with first of incoming data segment
if (!entities.isEmpty()) {
RubyString last = ((RubyString) input.pop(context));
RubyString nextFirst = ((RubyString) entities.shift(context));
entities.unshift(last.concat(nextFirst));
input.addAll(entities);
input.concat(entities);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ public void shouldNotChangeEncodingOfTokensAfterPartitioning() {

// verify encoding "ISO8859-1" is preserved in the Java to Ruby String conversion
RubyEncoding encoding = (RubyEncoding) firstToken.callMethod(context, "encoding");
assertEquals("ISO8859-1", encoding.toString());
assertEquals("ISO-8859-1", encoding.toString());
}
}

0 comments on commit a84656e

Please sign in to comment.