Skip to content

Commit

Permalink
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -435,9 +435,16 @@ public Object matchGeneric(VirtualFrame frame, DynamicObject regexp, DynamicObje
}

// Creating a MatchData will store a copy of the source string. It's tempting to use a rope here, but a bit
// inconvenient because we can't work with ropes directly in Ruby (useful for implementing some MatchData
// methods). Likewise, we need to taint objects based on the source string's taint state. We mustn't allow the
// source string's contents to change, however, so we must ensure that we have a private copy of that string.
// inconvenient because we can't work with ropes directly in Ruby and some MatchData methods are nicely
// implemented using the source string data. Likewise, we need to taint objects based on the source string's
// taint state. We mustn't allow the source string's contents to change, however, so we must ensure that we have
// a private copy of that string. Since the source string would otherwise be a reference to string held outside
// the MatchData object, it would be possible for the source string to be modified externally.
//
// Ex. x = "abc"; x =~ /(.*)/; x.upcase!
//
// Without a private copy, the MatchData's source could be modified to be upcased when it should remain the
// same as when the MatchData was created.
private Object matchWithStringCopy(DynamicObject regexp, DynamicObject string) {
final Matcher matcher = createMatcher(getContext(), regexp, string);
final int range = StringOperations.rope(string).byteLength();

0 comments on commit bee562d

Please sign in to comment.