Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix content clickable when having HTML attributes with "<" in the value #39931

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions projects/plugins/wpcomsh/changelog/fix-content-clickable
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fix function that add links to URLs in the page when having HTML attributes with "<" in the value
7 changes: 5 additions & 2 deletions projects/plugins/wpcomsh/tests/test-wpcomsh.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function test_wpcomsh_make_content_clickable() {
$div_skip = '<div class="skip-make-clickable test">https://wp.com</div>';
$custom_element = '<custom-element>https://wp.com</custom-element>';
$custom_element_starts_with_pre = '<presto-player>https://wp.com</presto-player>';
$link_inside_tag_inside_attr = "\n" . '<li data-test="<a href=\&quot;https://wp.com\&quot;&gt;Link</a&gt;"></li>';

$original_content = '' .
$script .
Expand All @@ -40,7 +41,8 @@ public function test_wpcomsh_make_content_clickable() {
$textarea .
$div_skip .
$custom_element .
$custom_element_starts_with_pre;
$custom_element_starts_with_pre .
$link_inside_tag_inside_attr;

$expected_output = '' .
'<script>https://wp.com</script>' .
Expand All @@ -52,7 +54,8 @@ public function test_wpcomsh_make_content_clickable() {
'<textarea>https://wp.com</textarea>' .
'<div class="skip-make-clickable test">https://wp.com</div>' .
'<custom-element><a href="https://wp.com" rel="nofollow">https://wp.com</a></custom-element>' . // Made clickable
'<presto-player><a href="https://wp.com" rel="nofollow">https://wp.com</a></presto-player>'; // Made clickable even if it starts with `<pre`
'<presto-player><a href="https://wp.com" rel="nofollow">https://wp.com</a></presto-player>' . // Made clickable even if it starts with `<pre`
"\n" . '<li data-test="<a href=\&quot;https://wp.com\&quot;&gt;Link</a&gt;"></li>'; // Don't make clickable if it's inside a tag inside an attribute.

$this->assertEquals( $expected_output, wpcomsh_make_content_clickable( $original_content ) );
}
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/wpcomsh/wpcomsh.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ function wpcomsh_make_content_clickable( $content ) {
// don't look in <a></a>, <pre></pre>, <script></script> and <style></style>
// use <div class="skip-make-clickable"> in support docs where linkifying
// breaks shortcodes, etc.
$_split = preg_split( '/(<[^<>]+>)/i', $content, -1, PREG_SPLIT_DELIM_CAPTURE );
$_split = preg_split( '/(<[^>]+>)/i', $content, -1, PREG_SPLIT_DELIM_CAPTURE );
$end = '';
$out = '';
$combine = '';
Expand Down
Loading