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

Projects
None yet
2 participants
@westonruter
Copy link
Member

westonruter commented May 5, 2018

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 added some commits May 5, 2018

Use possessive quantifiers for amp-bind regexes to prevent PREG_BACKT…
…RACK_LIMIT_ERRORs

Update dev-lib to fix unit test config failure

@westonruter westonruter added this to the v1.0 milestone May 5, 2018

@westonruter westonruter requested a review from kienstra May 5, 2018

@amedina

amedina approved these changes May 5, 2018

Copy link
Member

amedina left a comment

LGTM; awesome RegExp magic.

@westonruter westonruter merged commit 03f12f2 into develop May 5, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@westonruter westonruter deleted the fix/convert-amp-bind-attributes branch May 5, 2018

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