diff --git a/CHANGELOG b/CHANGELOG index bcb5e35..9d1d019 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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] diff --git a/src/string.js b/src/string.js index 5b47ca7..2c7ff8e 100644 --- a/src/string.js +++ b/src/string.js @@ -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) { diff --git a/test/unit/string.html b/test/unit/string.html index 30ec773..7632754 100644 --- a/test/unit/string.html +++ b/test/unit/string.html @@ -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) {