Skip to content

Conversation

@westonruter
Copy link
Member

@westonruter westonruter commented Mar 31, 2022

Fixes #512

Ensures that SelfClosingSVGElements will properly process:

  • SVG DOM trees that contain newlines.
  • SVG self-closing that have no whitespace (e.g. <path/> as opposed to <path />).

@westonruter westonruter added this to the 0.11.0 milestone Mar 31, 2022
'<!DOCTYPE html><html>' . $head . '<body>' . PHP_EOL
. '<svg>' . PHP_EOL
. ' <g id="ok">' . PHP_EOL
. ' <path/>' . PHP_EOL
Copy link
Member Author

Choose a reason for hiding this comment

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

This is currently failing in assertSimilarMarkup:

1) AmpProject\Dom\DocumentTest::testSVGSelfClosingElements with data set "test g tag one path child and newlines" ('<!DOCTYPE html><html><head></.../html>', '<!DOCTYPE html><html><head><m.../html>')
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     5 => '<body>'
     6 => '<svg>'
     7 => '<g id="ok">'
-    8 => '<path/>'
+    8 => '<path>'
     9 => '</g>'
     10 => '</svg>'
     11 => '</body>'
     12 => '</html>'
 )

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in cb091ed by using assertEqualMarkup instead of assertSimilarMarkup.

@westonruter westonruter marked this pull request as ready for review March 31, 2022 19:39
@westonruter
Copy link
Member Author

@schlessera Once this is merged, can a 0.11.0 release be made so we can include it in AMP plugin v2.2.2?


if (null === $regexPattern) {
$regexPattern = '#<(' . implode('|', self::SELF_CLOSING_TAGS) . ')((?>\s+[^/>]*))/?>(?!.*</\1>)#i';
$regexPattern = '#<(' . implode('|', self::SELF_CLOSING_TAGS) . ')((?>\s*[^/>]*))/?>(?!.*</\1>)#is';
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously .* would stop processing once it got to the end of a line. Now it will continue on to the end of the document. So that is something to be wary of.

@schlessera schlessera merged commit 842ceec into main Apr 1, 2022
@schlessera schlessera deleted the fix/self-closing-non-empty-g-element branch April 1, 2022 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SelfClosingSVGElements document filter erroneously self-closes g tags

4 participants