Make WordPress Core


Ignore:
Timestamp:
04/01/2022 03:38:55 AM (5 years ago)
Author:
peterwilsoncc
Message:

Formatting: Account for HTML entities in wp_extract_urls().

Prevent wp_extract_urls() trimming HTML entities within URLs. Correctly escaped URLs such as ​https://youtube.com/watch?v=dQw4w9WgXcQ&t=1 will now be extracted as ​https://youtube.com/watch?v=dQw4w9WgXcQ&t=1 rather than truncated.

Props trex005, voldemortensen, johnbillion, ironprogrammer, costdev, hellofromtonya.
Fixes #30580

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions.php

    r52932 r53044  
    991991                        'http://www.woo.com/video?v=exvUH2qKLTU',
    992992                        'http://taco.com?burrito=enchilada#guac',
     993                        'http://example.org/?post_type=post&p=4',
     994                        'http://example.org/?post_type=post&p=5',
     995                        'http://example.org/?post_type=post&p=6',
     996                        'http://typo-in-query.org/?foo=bar&ampbaz=missing_semicolon',
    993997                );
    994998
    … …  
    10531057
    10541058                        http://taco.com?burrito=enchilada#guac
     1059
     1060                        http://example.org/?post_type=post&p=4
     1061                        http://example.org/?post_type=post&p=5
     1062                        http://example.org/?post_type=post&p=6
     1063
     1064                        http://typo-in-query.org/?foo=bar&ampbaz=missing_semicolon
    10551065                ';
    10561066
    … …  
    10951105                $this->assertCount( 8, $urls );
    10961106                $this->assertSame( array_slice( $original_urls, 0, 8 ), $urls );
     1107        }
     1108
     1109        /**
     1110         * Tests for backward compatibility of `wp_extract_urls` to remove unused semicolons.
     1111         *
     1112         * @ticket 30580
     1113         *
     1114         * @covers ::wp_extract_urls
     1115         */
     1116        public function test_wp_extract_urls_remove_semicolon() {
     1117                $expected = array(
     1118                        'http://typo.com',
     1119                        'http://example.org/?post_type=post&p=8',
     1120                );
     1121                $actual   = wp_extract_urls(
     1122                        '
     1123                                http://typo.com;
     1124                                http://example.org/?post_type=;p;o;s;t;&p=8;
     1125                        '
     1126                );
     1127
     1128                $this->assertSame( $expected, $actual );
    10971129        }
    10981130
Note: See TracChangeset for help on using the changeset viewer.