Skip to content

Commit

Permalink
Change regex to accept single or no quote, add test
Browse files Browse the repository at this point in the history
Weston mentioned that this could have
single or no quotes.
I hadn't thought of that.
  • Loading branch information
kienstra committed Feb 25, 2020
1 parent 5ef39b7 commit 83d3dd6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Dom/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ private function maybe_restore_noscript_elements( $html ) {
*/
private function replace_mustache_templates( $html ) {
return preg_replace(
'#<script(\s[^>]*template="amp-mustache"[^>]*)>(.*?)</script>#s',
'#<script(\s[^>]*template=["\']?amp-mustache["\']?[^>]*)>(.*?)</script>#s',
'<tmp-script$1>$2</tmp-script>',
$html
);
Expand Down
5 changes: 5 additions & 0 deletions tests/php/test-class-amp-dom-document.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ public function data_dom_document() {
'<!DOCTYPE html><html>' . $head . '<body><script id="baz" type="text/plain" template="amp-mustache"><table><tr>{{#example}}<td></td>{{/example}}</tr></table></script></body></html>',
'<!DOCTYPE html><html>' . $head . '<body><script id="baz" type="text/plain" template="amp-mustache"><table><tr>{{#example}}<td></td>{{/example}}</tr></table></script></body></html>',
],
'amp_mustache_template_single_quotes' => [
'utf-8',
'<!DOCTYPE html><html>' . $head . '<body><script type=\'text/plain\' template=\'amp-mustache\'><table><tr>{{#example}}<td></td>{{/example}}</tr></table></script></body></html>',
'<!DOCTYPE html><html>' . $head . '<body><script type="text/plain" template="amp-mustache"><table><tr>{{#example}}<td></td>{{/example}}</tr></table></script></body></html>',
],
'amp_mustache_script_multiple_children' => [
'utf-8',
'<!DOCTYPE html><html>' . $head . '<body><script type="text/plain" template="amp-mustache"><h1>{{heading}}</h1><p>{{content}}</p><table><tr>{{#example}}<td></td>{{/example}}</tr></table></script></body></html>',
Expand Down

0 comments on commit 83d3dd6

Please sign in to comment.