WordPress.org

Make WordPress Core

Opened 8 weeks ago

Last modified 8 weeks ago

#52235 new defect (bug)

wp_extract_urls doesn't match localhost

Reported by: seanleavey Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.6
Component: General Keywords:
Focuses: Cc:

Description

The wp_extract_urls function does not match URLs with localhost as the domain:

<?php
// Matches.
wp_extract_urls("<a href=\"http://localhost.com:8889/?p=9\">hi</a>");

// Doesn't match.
wp_extract_urls("<a href=\"http://localhost:8889/?p=9\">hi</a>");

I think this function should definitely match localhost because this is often used in testing environments. But if this is intended behaviour, then the documentation makes no mention that this function only matches a subset of allowed URLs.

Change History (1)

#1 @seanleavey
8 weeks ago

This may also be related, but it seems that WordPress's testing bootstrap doesn't set the home_url() to the contents of the constant WP_TESTS_DOMAIN, so new posts created by e.g. $this->factory->post->create() inside unit tests have their permalink set to localhost (or presumably whatever the default is for the platform). This means that creating a post in a test with post_content set to contain a link to another post (retrieved via get_permalink( $other_post )), then running wp_extract_urls on its content, results in an array that doesn't contain the other post's URL.

Actually this was a problem on my end (the stuff immediately above, not the original issue).

Last edited 8 weeks ago by seanleavey (previous) (diff)
Note: See TracTickets for help on using tickets.