[wp-trac] [WordPress Trac] #53553: strpos(): Empty needle in /wp-includes/l10n.php on line 1047

WordPress Trac noreply at wordpress.org
Tue Jun 29 20:50:09 UTC 2021


#53553: strpos(): Empty needle in /wp-includes/l10n.php on line 1047
--------------------------+---------------------
 Reporter:  gwviger       |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  5.9
Component:  I18N          |     Version:  5.7.2
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+---------------------
Changes (by SergeyBiryukov):

 * component:  General => I18N
 * milestone:  Awaiting Review => 5.9


Old description:

> There was a previous ticket for a similar problem
> [https://core.trac.wordpress.org/ticket/46387#ticket] 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
> <?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
> <?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
> <?php
> ||  empty($content_url['path'])
> }}}
>

>

> Fixed code:
>

> {{{#!php
> <?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'] )
>         )
>
> }}}

New description:

 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
 <?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
 <?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
 <?php
 ||  empty($content_url['path'])
 }}}




 Fixed code:


 {{{#!php
 <?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'] )
         )

 }}}

--

Comment:

 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
 > <?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
 <?php
 define('WP_CONTENT_URL', $_SERVER['HTTP_HOST'])
 }}}

 It also causes a [https://www.php.net/manual/en/migration72.deprecated.php
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53553#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list