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

Fix handling of amp-bind attributes to ensure that “>” can appear inside attribute values #1119

Merged
merged 2 commits into from
May 5, 2018

Conversation

westonruter
Copy link
Member

Spurred on by @surma's post: My most useful RegExp trick.

The key part to getting this to work on large data sets was something new to me in regex: Possessive Quantifiers. This prevents backtracking and avoids PREG_BACKTRACK_LIMIT_ERROR from happening.

So now WordPress-served responses can successfully include:

<body class="bar" [class]="bodyClasses.concat( isBar ? 'bar' : '' ).filter( className => '' != className )">

Whereas previously this would fail and cause '' != className )"> to be the first text content of the body element. With this PR it is no longer is it required to use &gt; in the attribute as a workaround.

There was no perceived change in performance between the old and new regex patterns.

Again, the reason for all of this regex replacing is because PHP's DOMDocument (via libxml) does not like the bracketed amp-bind attribute syntax. So we have to convert them prior to parsing and restore them after serializing.

@westonruter westonruter added this to the v1.0 milestone May 5, 2018
@westonruter westonruter requested a review from kienstra May 5, 2018 06:20
Copy link
Member

@amedina amedina left a comment

Choose a reason for hiding this comment

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

LGTM; awesome RegExp magic.

@westonruter westonruter merged commit 03f12f2 into develop May 5, 2018
@westonruter westonruter deleted the fix/convert-amp-bind-attributes branch May 5, 2018 16:53
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

2 participants