How to exclude string value in javascript string?

I use to parse code (using an ES parser such as Esprima is not an option to limit the technical environment).

Subject code (processed code):

(function() {
    $('#3bf779cd').replaceWith("<div class=\'shows\'>\n<\/div>");

    window.fadeItems();
}).call(this);

The value that interests me is the first parameter replaceWith, which is a string literal. I get this variable with a regex:

const subjectValue = subjectCode.match(/\.replaceWith\(((["'])(?:(?=(\\?))\3.)*?\2)/m)[1].slice(1, -1);

console.log(subjectValue);

The result of this:

<div class=\'shows\'>\n<\/div>

How to avoid subjectValuein such a way that the result is:

<div class='shows'>
</div>

Just using unescapeit has no effect.

If I am not mistaken, the question arises of how to cancel this value:

console.log('"<div class=\\\'shows\\\'>\\\\n<\\\/div>"');
+4
source share
2

eval (, ):

text = document.querySelector('script').textContent;

dqString = /"(\\.|[^"])*"/g

s = text.match(dqString)[0]

raw = eval(s);

alert(raw);
<script>
(function() {
    $('#3bf779cd').replaceWith("<div class=\'shows\'>\n<\/div>");
    window.fadeItems();
});
</script>
Hide result
+2

.

"<div class=\\'shows\\'>\\\\n<\\/div>".replace(/\\n/g, '').replace(/\\/g, '');
// "<div class='shows'></div>"

unescape\n, , , .

0

Source: https://habr.com/ru/post/1630074/


All Articles