Make WordPress Core

Opened 4 weeks ago

Closed 4 weeks ago

#62972 closed defect (bug) (fixed)

Fatal error in twentyfourteen_paging_nav()

Reported by: takayukister's profile takayukister Owned by: audrasjb's profile audrasjb
Milestone: 6.8 Priority: normal
Severity: normal Version:
Component: Bundled Theme Keywords:
Focuses: Cc:

Description (last modified by sabernhardt)

You get the following error when you access the home page with GET variables in the array format. Example:

/?test[]=1

Fatal error: Uncaught TypeError: urlencode(): Argument #1 ($string) must be of type string, array given in /wp-content/themes/twentyfourteen/inc/template-tags.php:50

Stack trace:
#0 [internal function]: urlencode(Array)
#1 /wp-content/themes/twentyfourteen/inc/template-tags.php(50): array_map('urlencode', Array)
#2 /wp-content/themes/twentyfourteen/index.php(46): twentyfourteen_paging_nav()
#3 /wp-includes/template-loader.php(106): include('/Users/...')
#4 /wp-blog-header.php(19): require_once('/test...')
#5 /index.php(17): require('/test...')
#6 {main} thrown in /wp-content/themes/twentyfourteen/inc/template-tags.php on line 50

This error occurs because twentyfourteen_paging_nav() does not expect array variables.

A possible fix for this would be replacing array_map( 'urlencode', $query_args ) with urlencode_deep( $query_args ).

Attachments (3)

Screen Recording 2025-02-16 at 11.21.24 AM.mov (3.0 MB) - added by pratiklondhe 4 weeks ago.
62972.diff (710 bytes) - added by pratiklondhe 4 weeks ago.
t14-error-report.png (147.9 KB) - added by rinkalpagdar 4 weeks ago.

Change History (12)

#1 @sabernhardt
4 weeks ago

  • Component changed from Themes to Bundled Theme
  • Description modified (diff)
  • Version trunk deleted

#2 @pratiklondhe
4 weeks ago

hi, @takayukister , I tried to replicate this on fresh WP install and twentyfourteen theme but couldn't, I am able to access the homepage even withe the ?test[]=1 get parameter without error, is there some steps I am missing here ?

ps : attached a video of how I tested

#3 @takayukister
4 weeks ago

@pratiklondhe Maybe that is because you don't have enough number of posts. If you have 11 or more posts to show, twentyfourteen_paging_nav() will be used and the error will occur.

#4 @pratiklondhe
4 weeks ago

@takayukister , Yes, after adding 12 posts and testing again, I could replicate the issue.
I've implemented the changes you suggested, which appear to have resolved the error. Attaching the patch for review.

@pratiklondhe
4 weeks ago

#5 @audrasjb
4 weeks ago

  • Milestone changed from Awaiting Review to 6.8
  • Owner set to audrasjb
  • Status changed from new to reviewing

Thanks for the ticket, moving this to milestone 6.8.

#6 @rinkalpagdar
4 weeks ago

I have activated the twentyfourteen theme and also have 12 posts but couldn't able to reproduce the issue. Please let me know if I am missing anything here.
https:/core.trac.wordpress.org/attachment/ticket/62972/t14-error-report.png

#7 @pratiklondhe
4 weeks ago

Hey, @rinkalpagdar. Thanks for attempting to reproduce this!
Ideally, the homepage should display a list of posts. Could you check the backend settings by navigating to Settings → Reading → "Your homepage displays" and confirm that it's set to "Your latest posts" instead of a static page?

#8 @rinkalpagdar
4 weeks ago

Test Report

Description

This report validates whether the indicated patch works as expected.

Patch tested: https://core.trac.wordpress.org/attachment/ticket/62972/62972.diff

Environment

  • WordPress: 6.8-alpha-59274-src
  • PHP: 8.2.25
  • Server: nginx/1.27.2
  • Database: mysqli (Server: 8.0.40 / Client: mysqlnd 8.2.25)
  • Browser: Chrome 133.0.0.0
  • OS: macOS
  • Theme: Twenty Fourteen 4.1
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Actual Results

  1. ✅ Issue resolved with patch.

#9 @audrasjb
4 weeks ago

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

In 59851:

Bundled Themes: Prevent a fatal error occurring with Twenty Fourteen paginated navigation.

This changeset replaces array_map( 'urlencode', $query_args ) with urlencode_deep( $query_args ) in twentyfourteen_paging_nav() to prevent a fatal error when an array is provided in the query vars.

Props takayukister, pratiklondhe, rinkalpagdar.
Fixes #62972.

Note: See TracTickets for help on using tickets.