[wp-trac] [WordPress Trac] #53293: add_query_arg returning a bad character
WordPress Trac
noreply at wordpress.org
Sat May 29 09:58:42 UTC 2021
#53293: add_query_arg returning a bad character
---------------------------------+------------------------------
Reporter: rafasashi | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 5.7.2
Severity: major | Resolution:
Keywords: needs-testing close | Focuses:
---------------------------------+------------------------------
Changes (by SergeyBiryukov):
* keywords: needs-testing => needs-testing close
* component: Charset => General
Comment:
Hi there, welcome back to WordPress Trac! Thanks for the report.
I could not reproduce the issue on a clean install. This code:
{{{
var_dump(
add_query_arg(
array(
'note1' => 'test',
'note2' => 'test',
'note3' => 'test',
),
'example.com'
)
);
}}}
Returns the correct result in the page source:
{{{
string(44) "example.com?note1=test¬e2=test¬e3=test"
}}}
That said, the browser does indeed convert `¬` to the `¬` character
also known as the "not sign" and represented as `¬` or `¬` or
`¬`.
To avoid that, you should run the result throught the `esc_url()`
function:
{{{
var_dump(
esc_url(
add_query_arg(
array(
'note1' => 'test',
'note2' => 'test',
'note3' => 'test',
),
'example.com'
)
)
);
}}}
That would escape the ampersand and would be correctly displayed in the
browser:
{{{
string(61) "http://example.com?note1=test¬e2=test¬e3=test"
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53293#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list