Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect parsing nesting #9

Open
6562680 opened this issue Jul 28, 2022 · 2 comments
Open

Incorrect parsing nesting #9

6562680 opened this issue Jul 28, 2022 · 2 comments

Comments

@6562680
Copy link

6562680 commented Jul 28, 2022

        $dom = Document::loadHtml(''
            . '<ul class="a">'
            /**/ . '<li>a1</li>'
            /**/ . '<li>'
            /****/ . '<ul class="b">'
            /******/ . '<li>b1</li>'
            /******/ . '<li>b2</li>'
            /****/ . '</ul>'
            /**/ . '</li>'
            /**/ . '<li>a2</li>'
            /**/ . '<li>'
            /****/ . '<ul class="b">'
            /******/ . '<li>b3</li>'
            /******/ . '<li>b4</li>'
            /****/ . '</ul>'
            /**/ . '</li>'
            . '</ul>'
        );

        echo count($dom->find('ul li')) . PHP_EOL; // 8, ok
        echo count($dom->find('ul > li')) . PHP_EOL; // 8, ok
        echo count($dom->find('ul.a > li')) . PHP_EOL; // 4, ok
        echo count($dom->find('ul.b > li')) . PHP_EOL; // 4, ok


        $dom = Document::loadHtml(''
            . '<ul class="a">'
            /**/ . '<li>a1</li>'
            /**/ . '<li>'
            /* -- `ul` was removed -- */
            /******/ . '<li>b1</li>'
            /******/ . '<li>b2</li>'
            /* -- `ul` was removed -- */
            /**/ . '</li>'
            /**/ . '<li>a2</li>'
            /**/ . '<li>'
            /* -- `ul` was removed -- */
            /******/ . '<li>b3</li>'
            /******/ . '<li>b4</li>'
            /* -- `ul` was removed -- */
            /**/ . '</li>'
            . '</ul>'
        );

        echo count($dom->find('ul li')) . PHP_EOL; // 8, ok
        echo count($dom->find('ul > li')) . PHP_EOL; // 8, what ?
        echo count($dom->find('ul > li > li')) . PHP_EOL; // 0, what ?
@6562680
Copy link
Author

6562680 commented Jul 28, 2022

One more example:

$dom = Document::loadHtml(''
    . '<ul class="a">'
    /**/ . '<li>a1</li>'
    /**/ . '<li>'
    /* -- `ul` was removed -- */
    /******/ . '<li>b1</li>'
    /******/ . '<li>b2</li>'
    /* -- `ul` was removed -- */
    /**/ . '</li>'
    /**/ . '<li>a2</li>'
    /**/ . '<li>'
    /* -- `ul` was removed -- */
    /******/ . '<li>b3</li>'
    /******/ . '<li>b4</li>'
    /* -- `ul` was removed -- */
    /**/ . '</li>'
    . '</ul>'
);

$domLi = $dom->find('li', -3);

$this->assertEquals('<li><li>b3</li><li>b4</li></li>', $domLi); // fails :( equals '<li>' without closing tag

@6562680
Copy link
Author

6562680 commented Jul 28, 2022

One more example. Thats all about the parser. Sorry me.

$document = Document::loadHtml(''
    . '<div>'
    /**/ . '<a href="#">2020 &lt; </a>'
    /**/ . '<a href="#">2020 < </a>'
    . '</div>'
);

$domDiv = $document->find('div', 0);
dd(array_map('strval', $domDiv->children())); // array:2 [ 0 => "2020 &lt;", 1 => "2020" ] // what? where's the outerhtml of each? why only textNodes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant