scinfu / SwiftSoup

SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)
https://scinfu.github.io/SwiftSoup/
MIT License
4.52k stars 345 forks source link

Apparent regression in 2.7.3 #277

Closed DD-P closed 2 months ago

DD-P commented 2 months ago

HTML with Javascript containing CDATA and '&&' hangs on parsing. This first occurs with commit fc06146aa4231a11c5c0f1976a800992566e6e7e

A test case modified from here is

import SwiftSoup
import XCTest

class SwiftSoupTests: XCTestCase {
    func testJavaScriptWithCDATA() throws {
        let html = """
            <!DOCTYPE html>
            <html>
            <body>

            <h1>JavaScript Comparison</h1>
            <h2>The && Operator (Logical AND)</h2>
            <p>The && operator returns true if both expressions are true, otherwise it returns false.</p>

            <p id="demo"></p>

            <script>
            <!--//--><![CDATA[//><!--
            let x = 6;
            let y = 3;

            document.getElementById("demo").innerHTML = 
            (x < 10 && y > 1) + "<br>" + 
            (x < 10 && y < 1);
            //--><!]]>
            </script>

            </body>
            </html>
        """
        _ = try SwiftSoup.parse(html)
    }
}
aehlke commented 2 months ago

Sorry, that was my regression

I confirm that this test hangs

aehlke commented 2 months ago

Minimal test case which hangs:

            <!DOCTYPE html>
            <script>
            <!--//-->
            &
            </script>

not CDATA, but something with the combination of the comment tag + the ampersand

aehlke commented 2 months ago

I fixed it in this PR: https://github.com/scinfu/SwiftSoup/pull/276

aehlke commented 2 months ago

Released: https://github.com/scinfu/SwiftSoup/releases/tag/2.7.4

moehrenzahn commented 2 months ago

Hi, I just wanted to quickly say thanks for your efforts to keep this library updated and working. I just ran into this issue on 2.7.3 and am highly relieved that a fix is already available. You are awesome!

aehlke commented 2 months ago

@moehrenzahn np, I appreciate the kind words. I'm using it in production for my own app that I've gone full-time on (Manabi Reader https://reader.manabi.io for learning Japanese) and now that I've made it fast enough to continue using, I'll be sticking with it likely for years to come. Can't promise continued stewardship but I'm happy to see through a couple upgrades so far at least.