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

2007-06-20 Mark Rowe <[email protected]>

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 <[email protected]>

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:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.