#46316 closed defect (bug) (fixed)
wp_targeted_link_rel corrupts JSON content
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.2.1 | Priority: | normal |
Severity: | normal | Version: | 5.1 |
Component: | Formatting | Keywords: | dev-feedback has-patch has-unit-tests |
Focuses: | Cc: |
Description
In [43732], via #43187, a wp_targeted_link_rel
callback was added to filter content before it's saved to the database.
This has broken and corrupted JSON data in the TablePress plugin. (TablePress uses a CPT in which it stores a JSON-encoded two-dimensional array.)
If a cell of that array contains a link with a target
attribute, like
<a href="https://example.com/" target="_blank">link</a>
,
this gets converted and saved as
<a href=\"https://example.com/\" target=\"_blank\" rel="noopener noreferrer">link</a>
with the rel="noopener noreferrer"
attribute being added but without espacing of "
. This results in the JSON being invalid when read again.
This already caused problems for core, in #45292, with the result of the filter being removed temporarily via [44714].
I could apply the same "fix" around the saving process in TablePress, however the issue also appears to native core screens of the CPT. Also, as this feature is somewhat security-related, and turning it off would not be the favorable choice.
I strongly assume that this also affects other places where stored JSON code (with HTML code for a link inside) is handled by wp_targeted_link_rel
.
Attachments (1)
Change History (10)
This ticket was mentioned in Slack in #forums by tobiasbg. View the logs.
6 years ago
#3
@
6 years ago
- Keywords dev-feedback added
Could the regex that searches for target
attributes be changed to only find those with "
but not \"
(JSON encoded) quotation marks around the attribute value?
#4
@
6 years ago
- Keywords has-patch has-unit-tests added
What about using the same delimiter for the injected rel
attribute, as for the existing target
attribute, i.e. if we have target=\"_blank\"
then add rel=\"noopener noreferrer\"
, else rel="noopener noreferrer"
?
This is the approach in 46316.diff.
#6
@
6 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 45348:
Related: #46321