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

Add <body> if it's missing #183

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

bytestream
Copy link
Contributor

@bytestream bytestream commented May 21, 2020

Prevents Hello, This is a test. from being removed when parsing <html>Hello, This is a test.<br />Does it work this time?</html>

A body element’s start tag may be omitted if the element is empty, or if the first thing inside the body element is not a space character or a comment, except if the first thing inside the body element is a meta, link, script, style, or template element.

https://www.w3.org/TR/2014/REC-html5-20141028/sections.html#the-body-element

@bytestream
Copy link
Contributor Author

Travis seems broken but there's one failing test:

There was 1 failure:

  1. Masterminds\HTML5\Tests\Parser\DOMTreeBuilderTest::testText
    Failed asserting that two strings are equal.
    --- Expected
    +++ Actual
    @@ @@
    -'Line 0, Col 0: Unexpected text. Ignoring: Foo'
    +'Line 0, Col 0: Unexpected head tag outside of head context.'

/home/kieran/PhpstormProjects/html5-php/test/HTML5/Parser/DOMTreeBuilderTest.php:465
/home/kieran/PhpstormProjects/html5-php/vendor/phpunit/phpunit/phpunit:61

        // The DomTreeBuilder has special handling for text when in before head mode.
        $html = '<!DOCTYPE html><html>
    Foo<head></head><body></body></html>';
        $doc = $this->parse($html);
        $this->assertEquals('Line 0, Col 0: Unexpected text. Ignoring: Foo', $this->errors[0]);
        $headElement = $doc->documentElement->firstChild;
        $this->assertEquals('head', $headElement->tagName);

Not sure how this case should be handled now. When saved it now outputs:

<html><head></head><body>
    Foo<head></head><body></body></body></html>

@bytestream
Copy link
Contributor Author

@goetas how about this version?

@goetas
Copy link
Member

goetas commented May 31, 2020

This looks better! (please give me some time to test this , recently i've been super busy 😢 )

@bytestream
Copy link
Contributor Author

No worries :)

@goetas
Copy link
Member

goetas commented Jan 11, 2023

@stof would you mind helping me with this ? what do you think about the change?

* Test for issue #166.
*
* @param $input
* @param $expected
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such @param without type is totally useless. either add the types or remove those phpdoc

test/HTML5/Html5Test.php Show resolved Hide resolved
test/HTML5/Html5Test.php Outdated Show resolved Hide resolved
@goetas
Copy link
Member

goetas commented Jan 19, 2023

I think that this has been figured out, can you please review it again?

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

Successfully merging this pull request may close these issues.

None yet

4 participants