cheeriojs / cheerio

The fast, flexible, and elegant library for parsing and manipulating HTML and XML.
https://cheerio.js.org
MIT License
28.58k stars 1.64k forks source link

<= in javascript being parsed as `<=>` tag and wrongly closed </=> #1322

Closed Abhijay closed 4 years ago

Abhijay commented 5 years ago

I am running a program which loads a web page and injects some javascript into the page. I load the file as a string, and inject it into a particular script.

The original javascript has a section with an if clause with a <= conditional in it. Here's the original function.

$(".crossword").on('DOMSubtreeModified', function () {
    //alert('changed')

    if (receiveCount <= 0) {
        if (guid && socketId) {
            var grid = currentGridState();
            socket.emit('new move', guid, socketId, grid);
        }
    } else {
        if (receiveCount > 0) receiveCount--;
    }
})

I inject the javascript after doing a file read.

$('#sockets').prepend(puzzleScript)

The javascript that ends up on the web page ends up modified to parse the <= as part of a tag. Why is this happening and how do I disable this behavior?

$(".xyz").on('DOMSubtreeModified', function () {
    //alert('changed')

    if (receiveCount <= 0) { if (guid && socketid) var grid="currentGridState();" socket.emit('new move', guid, socketid, grid); } else (receivecount> 0) receiveCount--;
    }

....

</#></script>
fb55 commented 5 years ago

Which version of cheerio are you using? The parsing behavior should be fixed in the current RC releases.

fb55 commented 4 years ago

Fixed on the 1.0.0-RC versions.