Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Truffle] Preserve encoding in newly generated strings from String#sl…
…ice.
  • Loading branch information
nirvdrum committed Feb 17, 2015
1 parent 598ea89 commit fe5d5d1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
24 changes: 0 additions & 24 deletions spec/truffle/tags/core/string/slice_tags.txt
@@ -1,39 +1,21 @@
fails:String#slice returns the character code of the character at the given index
fails:String#slice returns nil if index is outside of self
fails:String#slice calls to_int on the given index
fails:String#slice raises a TypeError if the given index is nil
fails:String#slice raises a TypeError if the given index can't be converted to an Integer
fails:String#slice with index, length returns the substring starting at the given index with the given length
fails:String#slice with index, length always taints resulting strings when self is tainted
fails:String#slice with index, length returns nil if the offset falls outside of self
fails:String#slice with index, length returns nil if the length is negative
fails:String#slice with index, length calls to_int on the given index and the given length
fails:String#slice with index, length raises a TypeError when idx or length can't be converted to an integer
fails:String#slice with index, length raises a TypeError when the given index or the given length is nil
fails:String#slice with index, length returns subclass instances
fails:String#slice with index, length handles repeated application
fails:String#slice with Range returns the substring given by the offsets of the range
fails:String#slice with Range returns nil if the beginning of the range falls outside of self
fails:String#slice with Range returns an empty string if range.begin is inside self and > real end
fails:String#slice with Range always taints resulting strings when self is tainted
fails:String#slice with Range returns subclass instances
fails:String#slice with Range calls to_int on range arguments
fails:String#slice with Range works with Range subclasses
fails:String#slice with Range handles repeated application
fails:String#slice with Regexp returns the matching portion of self
fails:String#slice with Regexp returns nil if there is no match
fails:String#slice with Regexp always taints resulting strings when self or regexp is tainted
fails:String#slice with Regexp returns an untrusted string if the regexp is untrusted
fails:String#slice with Regexp returns subclass instances
fails:String#slice with Regexp sets $~ to MatchData when there is a match and nil when there's none
fails:String#slice with Regexp, index returns the capture for the given index
fails:String#slice with Regexp, index always taints resulting strings when self or regexp is tainted
fails:String#slice with Regexp, index returns an untrusted string if the regexp is untrusted
fails:String#slice with Regexp, index returns nil if there is no match
fails:String#slice with Regexp, index returns nil if there is no capture for the given index
fails:String#slice with Regexp, index calls to_int on the given index
fails:String#slice with Regexp, index raises a TypeError when the given index can't be converted to Integer
fails:String#slice with Regexp, index raises a TypeError when the given index is nil
fails:String#slice with Regexp, index returns subclass instances
fails:String#slice with Regexp, index sets $~ to MatchData when there is a match and nil when there's none
fails:String#slice with Regexp, group returns the capture for the given name
Expand All @@ -42,15 +24,13 @@ fails:String#slice with Regexp, group returns the innermost capture for nested d
fails:String#slice with Regexp, group always taints resulting strings when self or regexp is tainted
fails:String#slice with Regexp, group returns nil if there is no match
fails:String#slice with Regexp, group raises an IndexError if there is no capture for the given name
fails:String#slice with Regexp, group raises a TypeError when the given name is not a String
fails:String#slice with Regexp, group raises an IndexError when given the empty String as a group name
fails:String#slice with Regexp, group returns subclass instances
fails:String#slice with Regexp, group sets $~ to MatchData when there is a match and nil when there's none
fails:String#slice with String returns other_str if it occurs in self
fails:String#slice with String taints resulting strings when other is tainted
fails:String#slice with String doesn't set $~
fails:String#slice with String returns nil if there is no match
fails:String#slice with String doesn't call to_str on its argument
fails:String#slice with String returns a subclass instance when given a subclass instance
fails:String#slice! with index deletes and return the char at the given position
fails:String#slice! with index returns nil if idx is outside of self
Expand All @@ -59,13 +39,10 @@ fails:String#slice! with index calls to_int on index
fails:String#slice! with index returns the character given by the character index
fails:String#slice! with index, length deletes and returns the substring at idx and the given length
fails:String#slice! with index, length always taints resulting strings when self is tainted
fails:String#slice! with index, length returns nil if the given position is out of self
fails:String#slice! with index, length returns nil if the length is negative
fails:String#slice! with index, length raises a RuntimeError if self is frozen
fails:String#slice! with index, length calls to_int on idx and length
fails:String#slice! with index, length returns subclass instances
fails:String#slice! with index, length returns the substring given by the character offsets
fails:String#slice! with index, length treats invalid bytes as single bytes
fails:String#slice! Range deletes and return the substring given by the offsets of the range
fails:String#slice! Range returns nil if the given range is out of self
fails:String#slice! Range always taints resulting strings when self is tainted
Expand All @@ -80,7 +57,6 @@ fails:String#slice! with Regexp returns nil if there was no match
fails:String#slice! with Regexp always taints resulting strings when self or regexp is tainted
fails:String#slice! with Regexp doesn't taint self when regexp is tainted
fails:String#slice! with Regexp returns subclass instances
fails:String#slice! with Regexp returns the matching portion of self with a multi byte character
fails:String#slice! with Regexp sets $~ to MatchData when there is a match and nil when there's none
fails:String#slice! with Regexp raises a RuntimeError on a frozen instance that is modified
fails:String#slice! with Regexp raises a RuntimeError on a frozen instance that would not be modified
Expand Down
Expand Up @@ -302,7 +302,7 @@ public RubyString getIndexInBounds(RubyString string, int index, UndefinedPlaceh
if (normalizedIndex < 0 || normalizedIndex >= bytes.length()) {
throw new UnexpectedResultException(getContext().getCoreLibrary().getNilObject());
} else {
return getContext().makeString(bytes.charAt(normalizedIndex));
return getContext().makeString(bytes.charAt(normalizedIndex), string.getByteList().getEncoding());
}
}

Expand All @@ -315,7 +315,7 @@ public Object getIndex(RubyString string, int index, UndefinedPlaceholder undefi
outOfBounds.enter();
return getContext().getCoreLibrary().getNilObject();
} else {
return getContext().makeString(bytes.charAt(normalizedIndex));
return getContext().makeString(bytes.charAt(normalizedIndex), string.getByteList().getEncoding());
}
}

Expand All @@ -333,7 +333,7 @@ public Object slice(RubyString string, RubyRange.IntegerFixnumRange range, Undef
final int end = string.normalizeIndex(range.getEnd());
final int excludingEnd = string.clampExclusiveIndex(range.doesExcludeEnd() ? end : end+1);

return getContext().makeString(javaString.substring(begin, excludingEnd));
return getContext().makeString(javaString.substring(begin, excludingEnd), string.getByteList().getEncoding());
}
}

Expand All @@ -349,7 +349,10 @@ public Object slice(RubyString string, int start, int length) {
} else {
final int end = Math.min(bytes.length(), begin + length);

return new RubyString(getContext().getCoreLibrary().getStringClass(), new ByteList(bytes, begin, end - begin));
final ByteList byteList = new ByteList(bytes, begin, end - begin);
byteList.setEncoding(string.getByteList().getEncoding());

return getContext().makeString(byteList);
}
}

Expand Down
Expand Up @@ -277,6 +277,10 @@ public RubyString makeString(char string) {
return makeString(Character.toString(string));
}

public RubyString makeString(char string, Encoding encoding) {
return makeString(Character.toString(string), encoding);
}

public RubyString makeString(ByteList bytes) {
return RubyString.fromByteList(coreLibrary.getStringClass(), bytes);
}
Expand Down

0 comments on commit fe5d5d1

Please sign in to comment.