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

Prevent saveHTML from munging amp-mustache curly braces via URL-encoding #906

Merged
merged 1 commit into from
Jan 26, 2018

Conversation

westonruter
Copy link
Member

Cherry-picked from #871. URL-encoding of braces in href attributes is a side effect of switching from saveXML to saveHTML in #891.

@westonruter westonruter added this to the v0.7 milestone Jan 26, 2018
@westonruter westonruter requested a review from ThierryA January 26, 2018 06:10
@westonruter
Copy link
Member Author

(Yes, this is yet something else that could be part of AMP_DOMDocument, but let's not go there quite yet.)

@@ -285,6 +333,14 @@ public static function get_content_from_dom_node( $dom, $node ) {

$html = self::restore_amp_bind_attributes( $html );

// Restore amp-mustache placeholders which were replaced to prevent URL-encoded corruption by saveHTML.
Copy link
Collaborator

@ThierryA ThierryA Jan 26, 2018

Choose a reason for hiding this comment

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

Perhaps something like the prototype replacement below would have been sufficient:

$html = preg_replace_callback(
	"#href=[\"|'](%7B.*%7D)?[\"|']+#",
	function( $matches ) {
		return urldecode( $matches[0] );
	},
	$html
);

If that works for you, it can be updated in another PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want to do replacements on encodings that were original. And I wanted to limit the replacements to braces.

@ThierryA ThierryA merged commit 029aa06 into develop Jan 26, 2018
@westonruter westonruter deleted the fix/mustache-url-encoding branch January 26, 2018 18:19
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.

2 participants