#51313 closed defect (bug) (fixed)
Incorrect regular expression in links_add_target function
Reported by: | antonlukin | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.6 | Priority: | normal |
Severity: | normal | Version: | 5.5.1 |
Component: | Formatting | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
links_add_target
function relies on a regular expression "!<($tags)([^>]*)>!i"
. It ignores cases where a tag is part of another tag, for example aside
.
$content = 'test <aside>test</aside> test'; $content = links_add_target( $content, '_blank', array( 'a' ) );
This code return test <aside target="_blank">test</aside> test
but it shouldn't.
Possible solution is to replace regexp with !<($tags)(\s[^>]*)?>!i
https://developer.wordpress.org/reference/functions/links_add_target/
Attachments (1)
Change History (7)
#3
@
4 years ago
My patch contains a bug. I will fix it shortly and send pull request to GitHub mirror.
#4
@
4 years ago
- Keywords has-unit-tests added; needs-unit-tests removed
- Milestone changed from Awaiting Review to 5.6
- Owner set to SergeyBiryukov
- Status changed from new to reviewing
dream-encode commented on PR #533:
4 years ago
#6
Merged into WP Core in https://core.trac.wordpress.org/changeset/48983
Note: See
TracTickets for help on using
tickets.
Patch to links_add_target function