krux / postscribe

Asynchronously write javascript, even with document.write.
MIT License
986 stars 156 forks source link

Postscribe detects a greater than sign inside a script as a closing tag and adds a data-ps-id that is breaking the code #509

Open diglez opened 3 years ago

diglez commented 3 years ago

I have a very specific situation in which I want to insert a code similar to the below using postscribe:

<img src="data:image/png,ft" style="display: none" onerror="
        (function(img) {
            console.log('dummy function');
            console.log('that references ' + img);
            //and also has a conditional sort of like this
           if (10 > 8) { console.log('obviously'); } // MAIN ISSUE IS HERE 
           else { console.log('but only works with less than'); }
        })(this);
    ">

I know it is quite a strange code but that's how we get it sometimes form clients. The issue is that the > sign in the conditional is being detected by postscribe as the closing > for the img, which is causing a data-ps-id to show up and break the js code...

Here's an example showing the code with a > sign and then again with a < sign. The one with < works fine and prints all the expected outputs.

Screen Shot 2021-04-09 at 12 16 18 PM