Changeset 23675 in webkit


Ignore:
Timestamp:
Jun 20, 2007 5:00:12 PM (17 years ago)
Author:
bdash
Message:

2007-06-20 Mark Rowe <mrowe@apple.com>

Reviewed by Mitz.

Fix http://bugs.webkit.org/show_bug.cgi?id=14244
Bug 14244: Data corruption when using a replace() callback function with data containing "$"

  • kjs/string_object.cpp: (KJS::replace): When 'replacement' is a function, do not replace $n placeholders in its return value. This matches the behaviour described in ECMA 262 3rd Ed section 15.5.4.1, and as implemented in Firefox.

2007-06-20 Mark Rowe <mrowe@apple.com>

Reviewed by Mitz.

Test for http://bugs.webkit.org/show_bug.cgi?id=14244
Bug 14244: Data corruption when using a replace() callback function with data containing "$"

  • fast/js/resources/string-replace-2.js: Update to test with 'replaceValue' being a function returning strings with "$n" placeholders.
  • fast/js/string-replace-2-expected.txt:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r23540 r23675  
     12007-06-20  Mark Rowe  <mrowe@apple.com>
     2
     3        Reviewed by Mitz.
     4
     5        Fix http://bugs.webkit.org/show_bug.cgi?id=14244
     6        Bug 14244: Data corruption when using a replace() callback function with data containing "$"
     7
     8        * kjs/string_object.cpp:
     9        (KJS::replace):  When 'replacement' is a function, do not replace $n placeholders in its return value.
     10        This matches the behaviour described in ECMA 262 3rd Ed section 15.5.4.1, and as implemented in Firefox.
     11
    1122007-06-14  Anders Carlsson  <andersca@apple.com>
    213
  • trunk/JavaScriptCore/kjs/string_object.cpp

    r21867 r23675  
    345345      pushSourceRange(sourceRanges, sourceRangeCount, sourceRangeCapacity, UString::Range(lastIndex, matchIndex - lastIndex));
    346346
     347      UString substitutedReplacement;
    347348      if (replacementFunction) {
    348349          int completeMatchStart = ovector[0];
     
    350351
    351352          args.append(jsString(matchString));
    352          
     353
    353354          for (unsigned i = 0; i < reg->subPatterns(); i++) {
    354355              int matchStart = ovector[(i + 1) * 2];
    355356              int matchLen = ovector[(i + 1) * 2 + 1] - matchStart;
    356              
     357
    357358              args.append(jsString(source.substr(matchStart, matchLen)));
    358359          }
     
    361362          args.append(jsString(source));
    362363
    363           replacementString = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(),
    364                                                         args)->toString(exec);
    365       }
    366      
    367       UString substitutedReplacement = substituteBackreferences(replacementString, source, ovector, reg);
     364          substitutedReplacement = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(),
     365                                                             args)->toString(exec);
     366      } else
     367          substitutedReplacement = substituteBackreferences(replacementString, source, ovector, reg);
     368
    368369      pushReplacement(replacements, replacementCount, replacementCapacity, substitutedReplacement);
    369370
  • trunk/LayoutTests/ChangeLog

    r23661 r23675  
     12007-06-20  Mark Rowe  <mrowe@apple.com>
     2
     3        Reviewed by Mitz.
     4
     5        Test for http://bugs.webkit.org/show_bug.cgi?id=14244
     6        Bug 14244: Data corruption when using a replace() callback function with data containing "$"
     7
     8        * fast/js/resources/string-replace-2.js: Update to test with 'replaceValue' being a function returning strings with "$n" placeholders.
     9        * fast/js/string-replace-2-expected.txt:
     10
    1112007-06-20  Mitz Pettel  <mitz@webkit.org>
    212
  • trunk/LayoutTests/fast/js/resources/string-replace-2.js

    r11995 r23675  
    1616shouldBe("testString.replace(/([aeiou])([a-z])/g, function Capitalize(orig,re1,re2) { return re1.toUpperCase()+re2; })",
    1717        "\"It's the End Of the wOrld As we knOw It, And I fEel fIne.\"");
     18shouldBe("testString.replace(/(.*)/g, function replaceWithDollars(matchGroup) { return '$1'; })", "\"$1$1\"");
     19shouldBe("testString.replace(/(.)(.*)/g, function replaceWithMultipleDollars(matchGroup) { return '$1$2'; })", "\"$1$2\"");
     20shouldBe("testString.replace(/(.)(.*)/, function checkReplacementArguments() { return arguments.length; })", "\"5\"");
    1821
    1922var successfullyParsed = true;
  • trunk/LayoutTests/fast/js/string-replace-2-expected.txt

    r12001 r23675  
    1010PASS testString.replace(/([aeiou])([a-z])/g, function Capitalize(){ return RegExp.$1.toUpperCase()+RegExp.$2; }) is "It's the End Of the wOrld As we knOw It, And I fEel fIne."
    1111PASS testString.replace(/([aeiou])([a-z])/g, function Capitalize(orig,re1,re2) { return re1.toUpperCase()+re2; }) is "It's the End Of the wOrld As we knOw It, And I fEel fIne."
     12PASS testString.replace(/(.*)/g, function replaceWithDollars(matchGroup) { return '$1'; }) is "$1$1"
     13PASS testString.replace(/(.)(.*)/g, function replaceWithMultipleDollars(matchGroup) { return '$1$2'; }) is "$1$2"
     14PASS testString.replace(/(.)(.*)/, function checkReplacementArguments() { return arguments.length; }) is "5"
    1215PASS successfullyParsed is true
    1316
Note: See TracChangeset for help on using the changeset viewer.