Make WordPress Core


Ignore:
Timestamp:
09/10/2013 03:17:51 AM (11 years ago)
Author:
wonderboymusic
Message:

Replace the ancient phpfreaks.com RegEx to extract urls to ping with a more robust matcher. URLs with commas and things like & were not being pinged. The new matcher even works for most IDN URLs. Adds unit tests.

Fixes #9064.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r25139 r25313  
    18281828    $pung = get_pung($post_ID);
    18291829
    1830     // Variables
    1831     $ltrs = '\w';
    1832     $gunk = '/#~:.?+=&%@!\-';
    1833     $punc = '.:?\-';
    1834     $any = $ltrs . $gunk . $punc;
    1835 
    18361830    // Step 1
    18371831    // Parsing the post, external links (if any) are stored in the $post_links array
    1838     // This regexp comes straight from phpfreaks.com
    1839     // http://www.phpfreaks.com/quickcode/Extract_All_URLs_on_a_Page/15.php
    1840     preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp);
     1832    $post_links_temp = wp_extract_urls( $content );
    18411833
    18421834    // Step 2.
     
    18491841    // We don't wanna ping first and second types, even if they have a valid <link/>
    18501842
    1851     foreach ( (array) $post_links_temp[0] as $link_test ) :
     1843    foreach ( (array) $post_links_temp as $link_test ) :
    18521844        if ( !in_array($link_test, $pung) && (url_to_postid($link_test) != $post_ID) // If we haven't pung it already and it isn't a link to itself
    18531845                && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments.
Note: See TracChangeset for help on using the changeset viewer.