Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#49347 closed defect (bug) (fixed)

redirect_canonical() removing trailing punctuation from any query string arg ending in p

Reported by: daveslaughter's profile daveslaughter Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.4 Priority: normal
Severity: normal Version: 5.3.2
Component: Canonical Keywords:
Focuses: Cc:

Description

To reproduce add any query string with arg name ending p|page_id|cat|tag, and punctuation at the end of the value, e.g. "www.example.com/?comp=East+(North)"

Actual behaviour is to redirect to "www.example.com/?comp=East+(North".

Expected behaviour is to not redirect.

The problem is in the redirect_canonical function, specifically the regex to "Remove trailing spaces and end punctuation from certain terminating query string args.", which is

#(((p|page_id|cat|tag)=[^&]*?)($punctuation_pattern)+$#

The other regexes just after this code limit the query string args by making sure the complete arg name is checked, so the correct regex would be:

#((^|&)(p|page_id|cat|tag)=[^&]*?)($punctuation_pattern)+$#

Attachments (1)

redirect_canonical.diff (798 bytes) - added by daveslaughter 5 years ago.

Download all attachments as: .zip

Change History (4)

#1 @SergeyBiryukov
5 years ago

  • Component changed from General to Canonical
  • Milestone changed from Awaiting Review to 5.4
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

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

Introduced in [41991].

#2 @SergeyBiryukov
5 years ago

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

In 47169:

Canonical: When removing trailing punctuation from query string arguments, match the whole query var name.

Props daveslaughter.
Fixes #49347.

#3 @daveslaughter
5 years ago

Thanks for sorting so quickly. This is my first bug report, and I must say I'm impressed with the speed and efficiency of the response.

Note: See TracTickets for help on using tickets.