Description
Bug Description
I just discovered that certain plugins (example) may implement HTML compression that collapses whitespace and removes JS/CSS comments by means of regular expressions. For example (do not do this):
$buffer = preg_replace( '@\/\*(.*?)\*\/@s', ' ', $buffer );
This is dangerous and will often result in corrupted HTML markup.
This has the effect of turning this:
<p>This is an XPath: <code>/HTML/BODY/*[1][self::DIV]</code></p>
<p>This is a Script:</p>
<pre class="wp-block-code"><code><script>
/* example script */
</script></code></pre>
Into:
<p>This is an XPath: <code>/HTML/BODY </script></code></pre>
This is because the regular expression starts matching the supposed comment start in the first paragraph which mentions /HTML/BODY/*
and then it terminates the "comment" in the code sample in the third block.
This will break pages that contain data-od-xpath
attributes which Optimization Detective adds when detection is needed.
Granted, such regular expression logic will invariably cause many more problems than this, but we might want to consider hardening the data-od-xpath
attribute to prevent this from happening, namely by doing something like base64-encoding it in the attribute via base64_encode()
in PHP. It could then be converted back to the non-encoded form in JavaScript via atob()
.
Just something to consider.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status