From 38fa39af923915654df08ca21660095d267794f8 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 24 Jul 2007 16:30:19 +0000 Subject: [PATCH] prototype: Make String#scan explicitly return a string. Closes #6350. --- CHANGELOG | 2 ++ src/string.js | 2 +- test/unit/string.html | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) 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) {