Opened 11 months ago
Last modified 6 weeks ago
#63997 new defect (bug)
wptexturize incorrectly escapes attribute quotes after encountering greater-than sign
| Reported by: | icmcnamara | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Formatting | Version: | 6.8.2 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
Description
This appears to be a more generalized version of ticket https://core.trac.wordpress.org/ticket/63426.
The following examples could be run on the the 'init' action hook.
Using the greater-than character within attribute values causes the wptexturize function to incorrectly convert all proceeding quotation marks to decimal code.
<?php
$div_string = '<div data-template="Label <% value %>" data-label="{A \'message\' string}">Content</div>'
echo wptexturize( $div_string );
// Output:
// <div data-template="Label <% value %>” data-label=”{A ‘message’ string}”>Content</div>
// Expected output:
// <div data-template="Label <% value %>"; data-label="{A ‘message’ string}">Content</div>
This attribute quote escaping "resets" when a less-than symbol is encountered.
$div_string = '<div data-break="3>2" data-broken="b" data-fixer="<" data-working="1">Content</div>'; echo wptexturize( $div_string ); // Output: // <div data-break="3>2″ data-broken=”b” data-fixer=”<" data-working="1">Content</div>
Change History (7)
This ticket was mentioned in PR #12403 on WordPress/wordpress-develop by @nickchomey.
7 weeks ago
#2
- Keywords has-patch added
There was an error in the regex used in _get_wptexturize_split_regex and get_html_split_regex.
As shown in the associated trac ticket, if an HTML attribute contained >, the old regex treated it as the closing > for the element — the pattern [>]*> simply consumed everything up to the first > character.
The new regex instead accounts for quoted attribute values: when it encounters ' or " within a tag, it matches the entire quoted span (including any > inside) as a single atomic unit, using possessive quantifiers to avoid performance issues.
Trac ticket: 63997
## Use of AI Tools
@nickchomey commented on PR #12403:
7 weeks ago
#3
I made another commit that modified the regex a bit further (?:"[^"]*"|\'[^\']*\'|[^<>])*+> in order to handle the edge case in https://core.trac.wordpress.org/ticket/43785. It required some other test cases to change though, but I dont think it matters - it now texturizes invalid html/content.
@nickchomey commented on PR #12403:
7 weeks ago
#4
Also took the liberty of addressing a comment in _get_wptexturize_split_regex to replace it with get_html_split_regex(). All tests still pass.
@nickchomey commented on PR #12403:
6 weeks ago
#5
I went ahead and added/fixed types and docblocks for all the functions in the two files. Let me know if that was excessive and should be reverted...
@westonruter commented on PR #12403:
6 weeks ago
#6
I went ahead and added/fixed types and docblocks for all the functions in the two files. Let me know if that was excessive and should be reverted...
IMO, always better to fix these things up while touching the files already, like you're doing here. 👍🏻
@nickchomey commented on PR #12403:
6 weeks ago
#7
@westonruter is there anything remaining here that is blocking this from getting merged?
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
I just came across this exact issue with this html
The real cause is
_get_wptexturize_split_regex(), which produces this split (on the>)