Bug 213371 - A possible bug of String.prototype.replace
Summary: A possible bug of String.prototype.replace
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: PC Linux
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-06-19 04:24 PDT by NWU_NISL
Modified: 2020-06-30 09:03 PDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description NWU_NISL 2020-06-19 04:24:28 PDT
### Version: d940b47

### Testcase:
var NISLFuzzingFunc = function () {
    var a =  function (r) {
        return this[r];
    };
    print(a());
    var b = 'A@B#C$D.E'.replace(/([^A-Z])/g, a);
    print(b);
};
NISLFuzzingFunc();

### Command:
./webkit/WebKitBuild/Release/bin/jsc testcase.js

### Output:
undefined
AundefinedBundefinedC[object Object]DundefinedE

### Expected output:
undefined
AundefinedBundefinedCundefinedDundefinedE

### Description:
For String.prototype.replace (searchValue, replaceValue ), if the second parameter is a function, the matched string should be replaced with the return value of this function. When executing this test case, "$" should also be replaced with the return value of the function(undefined), but javascriptCore replaced it with [object Object]. I think this may be a bug of javascriptCore.


Contributor:Wen Yi
Comment 1 Radar WebKit Bug Importer 2020-06-19 17:21:55 PDT
<rdar://problem/64550276>
Comment 2 Alexey Shvayka 2020-06-30 09:03:22 PDT
(In reply to NWU_NISL from comment #0)
> ### Description:
> For String.prototype.replace (searchValue, replaceValue ), if the second
> parameter is a function, the matched string should be replaced with the
> return value of this function. When executing this test case, "$" should
> also be replaced with the return value of the function(undefined), but
> javascriptCore replaced it with [object Object]. I think this may be a bug
> of javascriptCore.

"$" is substituted with the value of `globalThis.$`, which is exposed to JSC shell (we use it in JSTests/stress), but not to the web.
If provided test case is executed in Chrome DevTools, "$" is also substituted with `document.querySelector` helper.