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

WIP catch an edge case for parsing #20

Conversation

NightJar
Copy link
Contributor

At current any field with a Shortcode in it (e.g. [code] ) is translated
as expected into it's replacement content, however thanks to this html5
module it also comes accompanied by a random tag at the end.

At current any field with a Shortcode in it (e.g. [code] ) is translated
as expected into it's replacement content, however thanks to this html5
module it also comes accompanied by a random </img> tag at the end.
@NightJar NightJar self-assigned this Mar 15, 2018
@NightJar NightJar changed the title Add a test to catch an edge case for parsing WIP test to catch an edge case for parsing Mar 15, 2018
@NightJar NightJar changed the title WIP test to catch an edge case for parsing WIP catch an edge case for parsing Mar 15, 2018
@dhensby
Copy link
Contributor

dhensby commented Mar 18, 2018

that is so fantastically bizarre

@NightJar
Copy link
Contributor Author

NightJar commented Mar 18, 2018

Sure is, but it also appears to be 100% to do with the way we 'handle' shortcodes. In that we don't really handle them, we just throw regex at it and hope for the best, then inject invalid tags so we can find the reference again later. Have an upcoming PR for that too (proper parsing).

Upon outputting a void element, the html5 library in use previous to
this commit would mysteriously append closing tags to void elements -
i.e. <img /> would become <img></img>.

Reading upon the internet at large, this seems to be a known issue with
PHP's DOMDocument library, however I could not find a reason why the
html5 library at it's standard would not recreate the issue, however it
remained would within our framework (requiring only silverstripe/recipe-core
as a baseline to test this).

So this commit has found and employed the use of another library with
the same goal - making html5 easy to process. It appears to succeed
where the previous did not - the test previously added to trigger the
described undesirable functionality is now passing - there are no longer
any invalid closing tags present in HTMLValue output.

Please note that while the version of the new html5 processing library
in use is in fact an out of date one, it is the last version compatible
with PHP 5.6 - which we still support at this time.
@NightJar
Copy link
Contributor Author

NightJar commented Mar 19, 2018

Turns out no, 100% to do with some weird environmental thing with the backing library.
wew what a doozy - I could not replicate it with the library alone.

Expanded investigation lead to see that this will also solve #19

@robbieaverill robbieaverill merged commit 2ea6e5c into silverstripe:master Mar 19, 2018
@robbieaverill robbieaverill deleted the pulls/2.0/unclose-my-image branch March 19, 2018 10:09
@robbieaverill
Copy link
Contributor

Nice work :-)

return 'bit of test shortcode output';
}
);
$content = DBHTMLText::create('Test', ['shortcodes'=>true])
Copy link
Contributor

Choose a reason for hiding this comment

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

the => needs spaces around it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}
);
$content = DBHTMLText::create('Test', ['shortcodes'=>true])
->setValue('<p>Some content with a [test_shortcode] and a <br /> followed by an <hr> in it.</p>')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this test is testing 2 things (1. that the HTML parser moves <hr> out of its <p> and 2. that the shortcode is correctly parsed.

I don't think there's a need for the first test (the lib itself should be testing for this) but if you want to test it, it should be a separate test.

Copy link
Contributor Author

@NightJar NightJar Mar 19, 2018

Choose a reason for hiding this comment

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

No, you're right. It should be tested in the lib. And it shouldn't be an issue.
But neither should it feel the need to close void elements (nor do they in the lib tests).

The opportunity was there, I took it. It is valid in this test, and it is only testing that the <hr> doesn't render as <hr></hr>, I've simply left the comment to make clear why the tag order has rearranged in the expected output (for those who perhaps may not be aware).

There's no harm in double checking our facts where there's history of them being alternative ;)

@dhensby
Copy link
Contributor

dhensby commented Mar 19, 2018

@robbieaverill you're too keen, my man

@robbieaverill
Copy link
Contributor

@dhensby sorry, will follow up your feedback tomorrow with @NightJar :-)

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

Successfully merging this pull request may close these issues.

None yet

3 participants