WordPress.org

Make WordPress Core

Opened 3 months ago

Last modified 3 months ago

#53553 new defect (bug)

strpos(): Empty needle in /wp-includes/l10n.php on line 1047

Reported by: gwviger Owned by:
Milestone: 5.9 Priority: normal
Severity: normal Version: 5.7.2
Component: I18N Keywords: has-patch
Focuses: Cc:

Description (last modified by SergeyBiryukov)

There was a previous ticket for a similar problem #46387 that was resolved but a similar issue has appeared on line 1047 of /wp-includes/l10n.php. Existed in 5.6.x. Still exists in 5.7.2.

Seems problem shows up when wp-config.php includes:

<?php
define('WP_CONTENT_URL', $_SERVER[HTTP_HOST])

Issue: $content_url is returned as empty string "". strpos() creates notice on empty value as needle.

Current Code:

<?php
if (
                ( ! isset( $content_url['path'] )  || strpos( $src_url['path'], $content_url['path'] ) === 0 ) &&
                ( ! isset( $src_url['host'] ) || ! isset( $content_url['host'] ) || $src_url['host'] === $content_url['host'] )
        )

Fix is to add

<?php
||  empty($content_url['path'])

Fixed code:

<?php
if (
                ( ! isset( $content_url['path'] ) || empty($content_url['path']) || strpos( $src_url['path'], $content_url['path'] ) === 0 ) &&
                ( ! isset( $src_url['host'] ) || ! isset( $content_url['host'] ) || $src_url['host'] === $content_url['host'] )
        )

Change History (1)

#1 @SergeyBiryukov
3 months ago

  • Component changed from General to I18N
  • Description modified (diff)
  • Milestone changed from Awaiting Review to 5.9

Hi there, welcome to WordPress Trac! Thanks for the report.

This also seems similar to #49145 (fixed in [49639] for 5.6).

Seems problem shows up when wp-config.php includes:

<?php
define('WP_CONTENT_URL', $_SERVER[HTTP_HOST])

Just noting that this line sets WP_CONTENT_URL to an empty value due to incorrect quotes, these should be straight single quotes instead of ‘curly’ quotes:

<?php
define('WP_CONTENT_URL', $_SERVER['HTTP_HOST'])

It also causes a warning in PHP 7.2+:

Warning: Use of undefined constant ‘HTTP_HOST’ - assumed '‘HTTP_HOST’' (this will throw an Error in a future version of PHP)

And a fatal error on PHP 8:

Fatal error: Uncaught Error: Undefined constant "‘HTTP_HOST’"

Fixing the quotes should remove the notice, though I wonder if an empty WP_CONTENT_URL could cause other issues elsewhere, and whether this notice in load_script_textdomain() is currently the only indicator that something is wrong, in which case it might be helpful for debugging. Moving to 5.9 for investigation.

Note: See TracTickets for help on using tickets.