#44499 closed defect (bug) (fixed)
add_query_arg function doesn't remove the empty '?' when an anchor exists
Reported by: | benjamin.anakena | Owned by: | hellofromTonya |
---|---|---|---|
Milestone: | 5.9 | Priority: | normal |
Severity: | minor | Version: | 4.9.6 |
Component: | HTTP API | Keywords: | has-patch has-unit-tests commit |
Focuses: | Cc: |
Description
To reproduce:
<?php $url = 'https://domain.com/uri?param=value#anchor'; $url = add_query_arg( 'param', false, $url ); echo $url;
Expected value: https://domain.com/uri#anchor
Returned value: https://domain.com/uri?#anchor
Attachments (3)
Change History (15)
#1
@
4 years ago
- Keywords has-patch needs-testing added
@benjaminanakena Thanks for the report!
44499.patch works with the example.
#3
@
3 years ago
- Milestone changed from Awaiting Review to 5.9
- Owner set to sabernhardt
- Status changed from new to accepted
#4
@
3 years ago
- Keywords needs-unit-tests added
- Owner changed from sabernhardt to hellofromTonya
- Status changed from accepted to assigned
This ticket was mentioned in PR #1902 on WordPress/wordpress-develop by hellofromtonya.
3 years ago
#6
Applies patch 44499.1.diff.
Adds more test datasets.
Trac ticket: https://core.trac.wordpress.org/ticket/44499
@
3 years ago
Browser Test Report: same behavior before and after 44499.1.diff. No regression. Works before and after.
#7
@
3 years ago
- Keywords needs-testing removed
Test Report
Env:
- Browser: Chrome, Firefox, Edge, and Safari
- OS: macOS
- localhost: wp-env
- WordPress: trunk
- Theme: TT2
- Plugins: none
Steps
- Go to "Posts" and then "Add New"
- In the content, add some filler paragraphs.
- And then add a
header
block towards the bottom of the content. - With the
header
block selected, click on "Advanced" and set the "HTML anchor" toanchor
. - Set the permalinks to something other than "Plain".
- View the new post in the front-end
- Click in the browser's search bar and append
?param=value#anchor
to the end of the URL. Press enter or return.
The post should reload and jump to the header block.
- Apply the patch.
- Repeat step 6 and 7.
Should again jump to the header block.
- Repeat steps 6 to 7 using by appending this after the URL:
?#anchor
.
Should again jump to the header block.
Results
There is no bug or issue in the front-end as the browser handles the query args and jumps to the anchor ✅
With and without the patch, each browser behaved the same ✅
#8
@
3 years ago
- Keywords commit added
While the add_query_arg()
does not remove the unneeded ?
when there are no query args, it works in each browser tested. Granted it seems odd to leave ?
when it's not needed. But I wonder: Is there's a browser or device where this does not work?
For backend correctness, it makes sense to remove the unneeded ?
character. This can help with further processing where that character is not expected and guard Core against changes in browsers or incompatibility between apps and browsers.
PR 1902 is ready for commit
.
#11
@
3 years ago
- Component changed from General to HTTP API
Thank you everyone for contributing! The patch has been committed and will ship in 5.9.
hellofromtonya commented on PR #1902:
3 years ago
#12
Committed via changeset https://core.trac.wordpress.org/changeset/52187.
replace
?#
with#