Question

I was reading the JS from one page and this is what I found (the source is deobfuscated by google chrome dev tools):

var db = function(a) {
    return a.replace(/[^\w\s\.\|`]/g, 
    function(b) {
        return "\\" + b
    })
};

Is there a some trick with the first comma operator operand (the a.replace() one)?

From my point of view the a.replace(/[^\w\s\.\|``]/g, part is completely redundant and can be removed.

Have I missed something?

Was it helpful?

Solution

It is not the comma operator, but a simple arguments list of the call to .replace - notice the parenthesis.

Your deobfuscator better should've indented it like this:

return a.replace(/[^\w\s\.\|`]/g, function(b) {
    return "\\" + b;
});

Btw, that function could be replaced by the simple string "\\$&".

OTHER TIPS

There is no comma operator.

See the documentation for replace

newstring = str.replace(regexp, function);

The poor formatting makes it hard to read.

It's basically doing

a.replace(/([^\w\s\.\|`])/g, "\\$1");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top