prototype: Make String#scan explicitly return a string. Closes #6350.
This commit is contained in:
parent
513042dd98
commit
38fa39af92
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Make String#scan explicitly return a string. This prevents possible issues with methods expecting input data that is typeof == 'string'. Closes #6350. [AndrewRev, Tobie Langel]
|
||||
|
||||
* Add Array#intersect for set intersection. Returns a new array containing all items common to the array and the argument, with duplicates removed (clone of the Ruby & method). [Thomas Fuchs]
|
||||
Example:
|
||||
[1,1,3,5].intersect([1,2,3]) -> [1,3]
|
||||
|
|
|
@ -41,7 +41,7 @@ Object.extend(String.prototype, {
|
|||
|
||||
scan: function(pattern, iterator) {
|
||||
this.gsub(pattern, iterator);
|
||||
return this;
|
||||
return String(this);
|
||||
},
|
||||
|
||||
truncate: function(length, truncation) {
|
||||
|
|
|
@ -132,11 +132,12 @@
|
|||
|
||||
testScan: function() {with(this) {
|
||||
var source = 'foo boo boz', results = [];
|
||||
source.scan(/[o]+/, function(match) {
|
||||
var str = source.scan(/[o]+/, function(match) {
|
||||
results.push(match[0].length);
|
||||
});
|
||||
assertEnumEqual([2, 2, 1], results);
|
||||
assertEqual(source, source.scan(/x/, fail));
|
||||
assert(typeof str == 'string');
|
||||
}},
|
||||
|
||||
testToArray: function() {with(this) {
|
||||
|
|
Loading…
Reference in New Issue