Make WordPress Core

Opened 17 years ago

Last modified 4 weeks ago

#2877 assigned defect (bug)

A Slash too much @ get_pagenum_link()

Reported by: davemad-davenet's profile dave@… Owned by: petitphp's profile petitphp
Milestone: 6.4 Priority: normal
Severity: normal Version: 2.0
Component: Posts, Post Types Keywords: has-patch needs-testing has-unit-tests has-testing-info
Focuses: template Cc:

Description

  • File: template-functions-links.php
  • Function: get_pagenum_link()

The following code is at the end of the function:

	// showing /page/1/ or ?paged=1 is redundant
	if ( 1 === $pagenum ) {
		$qstr = str_replace('page/1/', '', $qstr); // for mod_rewrite style
		$qstr = remove_query_arg('paged', $qstr); // for query style
	}

If you work with the mod_rewrite style, you will get this URL for the first page:

http://www.example.com/wordpress/index.php/
This wont work (/ at the end).

Correx:

	// showing /page/1/ or ?paged=1 is redundant
	if ( 1 === $pagenum ) {
		$qstr = str_replace('/page/1/', '', $qstr); // for mod_rewrite style
		$qstr = remove_query_arg('paged', $qstr); // for query style
	}

Notes:

  • sry for my bad english...
  • i've downloaded a german translation of wordpress 2.0.3, so maybe its just in this version... ?!

Attachments (3)

2877.diff (1.4 KB) - added by scribu 12 years ago.
2877.2.diff (1.4 KB) - added by jesin 8 years ago.
Refresh 2877.diff
2877-test.diff (891 bytes) - added by jesin 8 years ago.

Download all attachments as: .zip

Change History (30)

#1 @darkfate
17 years ago

No, it's that way in the english version. I don't think that would fix it and there would be a problem with that. Putting the slash in front like you did would make the server redirect to root. So if you have wordpress in a directory it would screw up like so:
You would want this:
http://site.com/wordpress/testing/1/
But you would get this:
http://site.com/testing/1/

#2 @Nazgul
16 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

No traction in almost a year, so closing as wontfix.

Feel free to re-open it if you have additional information/suggestions/patches/...

#3 @scribu
12 years ago

  • Keywords needs-patch added
  • Milestone set to Future Release
  • Resolution wontfix deleted
  • Status changed from closed to reopened

Only enhancements or feature requests can be closed when there's no traction.

@scribu
12 years ago

#4 @scribu
12 years ago

  • Keywords has-patch added; needs-patch removed

#5 @scribu
12 years ago

Note that the problem is with first-page links, not with /page/2, /page/3/ etc.

Version 0, edited 12 years ago by scribu (next)

#6 @nacin
10 years ago

  • Component changed from General to Template

Interesting patch.

#7 @nacin
10 years ago

  • Keywords needs-unit-tests added

#8 @nacin
10 years ago

  • Component changed from Template to Posts, Post Types
  • Focuses template added

#9 @obenland
9 years ago

  • Keywords needs-refresh added

#10 @chriscct7
8 years ago

  • Version changed from 2.0.3 to 2.0

@jesin
8 years ago

Refresh 2877.diff

@jesin
8 years ago

#11 @mattheweppelsheimer
5 years ago

  • Keywords needs-testing added; needs-unit-tests needs-refresh removed

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


8 months ago

#13 @audrasjb
8 months ago

  • Keywords needs-refresh added
  • Owner set to petitphp
  • Status changed from reopened to assigned

We discussed this issue during this week Old Tickets Triage Session.

The patch needs to be refreshed. Assigning @petitphp who's willing to add a new patch/unit tests.

Thanks to @SergeyBiryukov, @maigret, @petitphp for discussing this issue :)

This ticket was mentioned in PR #3931 on WordPress/wordpress-develop by @petitphp.


8 months ago
#14

  • Keywords has-unit-tests added; needs-refresh removed

#15 @petitphp
8 months ago

PR with refreshed patch added.

I've made a change from the original patch to ensure query_args don't force a trailing slash, and I updated the tests accordingly.

I've tested multiple cases :

In every case, get_pagenum_link correctly matched the permalink structure and only added a trailing slash if present.

This should be ready for testing on more exotic WordPress install.

#16 @audrasjb
7 months ago

  • Milestone changed from Future Release to 6.3

Thanks for the PR @petitphp!
Moving for 6.3 consideration.

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


4 months ago

#18 follow-up: @mukesh27
4 months ago

  • Keywords has-testing-info added

This ticket was discussed in the recent bug scrub.

The PR looks good and requires manual testing. Could someone from the testing team, such as @ironprogrammer or @webtechpooja, please review it?

Additional props to @oglekler

#19 @oglekler
3 months ago

Unit tests need documentation to methods to clarify what will be tested, the purpose of this tests.
Besides, it still needs to be tested.

#20 @oglekler
3 months ago

  • Keywords changes-requested added

This ticket was mentioned in PR #4801 on WordPress/wordpress-develop by @costdev.


3 months ago
#21

Previously, a trailing slash was appended to the link returned from this function. If the permalink structure didn't contain a trailing slash, this link could fail.

This change removes trailing slashes and only appends one if the site is set for adding trailing slashes.

---

This PR is an update of #3931 which makes various test improvements, including:

  • Documentation updates.
  • Backing up some $_SERVER variables before any tests run, and restoring them after each test has run.
  • Using a data provider to group related datasets.
  • Adding datasets that account for index.php in the permalink structure.

#22 @costdev
3 months ago

  • Keywords changes-requested removed

@oglekler PR 4801 updates the previous PR with the requested documentation updates, as well as other improvements to the tests which are listed in the PR's description. The tests now cover 100% of the lines and branches touched by the patch.

Last edited 3 months ago by costdev (previous) (diff)

#23 in reply to: ↑ 18 @mai21
2 months ago

Replying to mukesh27:

This ticket was discussed in the recent bug scrub.

The PR looks good and requires manual testing. Could someone from the testing team, such as @ironprogrammer or @webtechpooja, please review it?

Additional props to @oglekler

@mukesh27 Thanks for your comment. May I ask what is the exact reproducible steps here from the user's perspective?

#24 @webtechpooja
2 months ago

I tried to reproduced the issue as described in the ticket. But couldn't make it.
The above mentioned links worked for me without using patch, so not sure about this patch.

Could you please guide me the steps to reproduce this issue. Thanks

#25 @audrasjb
2 months ago

Moving for 6.4 consideration as this still requires testing.

(@costdev feel free to ping me if you're confident this can ship before RC1)

#26 @audrasjb
2 months ago

  • Milestone changed from 6.3 to 6.4

#27 @petitphp
4 weeks ago

Hey @webtechpooja

I tried to reproduced the issue as described in the ticket. But couldn't make it.
The above mentioned links worked for me without using patch, so not sure about this patch.

Sorry, my first report wasn't clear on what and how to test this.

The original issue is that the get_pagenum_link function always add a slash at the end of the link to the first page of a post type or taxonomy archive even if the permalink structure doesn't contain one.

Could you please guide me the steps to reproduce this issue. Thanks

Here the steps to reproduce the issue and the expected result.

Given a WordPress install with TwentyTwentyThree theme :

  • Set the permalink structure to /%postname% (no trailing slash)
  • Create multiple posts (enough to have at least two pages)
  • On the frontend go to the year archive page (https://example.com/2023)
  • The Older Posts -> link should be https://example.com/2023/page/2 (no trailing slash, work as expected)
  • Go to the second page (https://example.com/2023/page/2)
  • The <- Newer Posts link should be https://example.com/2023 but the actual link is https://example.com/2023/ with a trailing slash (not working as expected).

The patch should fix the issue from the last step and remove the trailing slash of the first page link.

Let me know if you need additional information.

Note: See TracTickets for help on using tickets.