WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#28222 closed defect (bug) (fixed)

wp_extract_urls recognize a date as a url

Reported by: sergej.mueller Owned by: wonderboymusic
Milestone: 4.0 Priority: normal
Severity: normal Version: 3.7
Component: Pings/Trackbacks Keywords: has-patch
Focuses: Cc:

Description

wp_extract_urls("Today's Date: 05.12.2014")

has the following array as output

Array ( [0] => 05.12.2014 )

A date is not an IP address.

Attachments (3)

functions.php.patch (414 bytes) - added by sergej.mueller 7 years ago.
scheme-less.functions.php.patch (417 bytes) - added by sergej.mueller 7 years ago.
URL scheme-less check
28222.withtests.patch (4.6 KB) - added by hinnerk 7 years ago.
Added test cases, more readable regexp

Download all attachments as: .zip

Change History (15)

#1 @SergeyBiryukov
7 years ago

  • Component changed from Filesystem API to Pings/Trackbacks

#2 @SergeyBiryukov
7 years ago

  • Version changed from 3.9.1 to 3.7

Introduced in [25313].

#3 @ocean90
7 years ago

  • Keywords needs-patch needs-unit-tests added

#4 @sergej.mueller
7 years ago

  • Keywords has-patch added; needs-patch removed

@sergej.mueller
7 years ago

URL scheme-less check

@hinnerk
7 years ago

Added test cases, more readable regexp

#5 @hinnerk
7 years ago

  • Keywords needs-unit-tests removed

The function still will not extract "http://localhost/" as a "." is mandatory.
#WCHH14

Last edited 7 years ago by hinnerk (previous) (diff)

#6 @SergeyBiryukov
7 years ago

  • Milestone changed from Awaiting Review to 4.0

#7 @wonderboymusic
7 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 28882:

wp_extract_urls() should not match dates.

Updates unit tests.

Props hinnerk, sergej.mueller.
Fixes #28222.

#8 follow-up: @kovshenin
7 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

In r28882 since you're doing concatenation in PHP, you don't really need the x preg pattern modifier.

#9 in reply to: ↑ 8 ; follow-up: @SergeyBiryukov
7 years ago

Replying to kovshenin:

In r28882 since you're doing concatenation in PHP, you don't really need the x preg pattern modifier.

There are some new spaces in the regex itself, perhaps for better readability. I don't think they're necessary though.

#10 @hinnerk
7 years ago

I've added the /x modifier for better readability, only. I prefer doing this in longer regular expressions.
All whitespaces in the pattern are totally ignored (see http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php).

If you don't like, I will strip it.

#11 in reply to: ↑ 9 @kovshenin
7 years ago

Replying to SergeyBiryukov:

I don't think they're necessary though.

You're right, I missed those. I agree re necessity, I spotted 6 of them. The x modifier would be more useful if the regex was indeed a single string. So either concatenate with PHP and remove whitespace and the x modifier, or keep the x modifier and remove PHP newline concatenation, but not both.

#12 @SergeyBiryukov
7 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 28933:

Remove free-spacing modifier and extra spaces from wp_extract_urls() pattern.

fixes #28222.

Note: See TracTickets for help on using tickets.