Make WordPress Core

Opened 3 years ago

Closed 22 months ago

#53553 closed defect (bug) (wontfix)

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

Reported by: gwviger's profile gwviger Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.7.2
Component: I18N Keywords: close
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 (5)

#1 @SergeyBiryukov
3 years 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.

#2 @desrosj
2 years ago

  • Milestone changed from 5.9 to 6.0

This hasn't received any attention during the 5.9 cycle, so I'm punting to 6.0.

This ticket was mentioned in Slack in #core by costdev. View the logs.


23 months ago

#4 @costdev
23 months ago

  • Keywords close added; has-patch removed

Per the discussion in the bug scrub, I'm removing has-patch as one does not exist, and adding close as it was felt that using straight quotes '' is expected and that covering other quotes is not desired.

@SergeyBiryukov regarding the WP_CONTENT_URL question, do you think this is an issue and should have its own ticket for investigation?

#5 @costdev
22 months ago

  • Milestone 6.0 deleted
  • Resolution set to wontfix
  • Status changed from new to closed

As we're approaching RC1 and given that this warning/fatal appears due to invalid quotes in this case, I'm going to close this ticket as wontfix.

In terms of directly specifying WP_CONTENT_URL as empty, I'm not quite sure why someone would do that.

Regarding the potential investigation into an empty WP_CONTENT_URL constant causing issues elsewhere, this should be addressed in a separate ticket.

Note: See TracTickets for help on using tickets.