WordPress.org

Make WordPress Core

Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#53293 closed defect (bug) (worksforme)

add_query_arg returning a bad character

Reported by: rafasashi Owned by:
Milestone: Priority: normal
Severity: major Version: 5.7.2
Component: General Keywords:
Focuses: Cc:

Description

When add_query_arg is used with "not" at the beginning of a key (excluding the first parameter), the function seems to replace "&not" by "¬".

For example:

add_query_arg( array(
	'note1'=>'test',
	'note2'=>'test',
	'note3'=>'test',
),'example.com');

returns "example.com?note1=test¬e2=test¬e3=test"

Change History (3)

#1 follow-up: @SergeyBiryukov
5 months ago

  • Component changed from Charset to General
  • Keywords close added

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&note2=test&note3=test"

That said, the browser does indeed convert &not 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&note2=test&note3=test"
Last edited 5 months ago by SergeyBiryukov (previous) (diff)

#2 in reply to: ↑ 1 @rafasashi
5 months ago

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

Replying to SergeyBiryukov

Hello Sergey,

Thank you for taking the time to test this issue.

I confirm that it works ok after using esc_url().

So it was not a major issue after all, lesson learned.

#3 @SergeyBiryukov
5 months ago

  • Keywords needs-testing close removed
  • Milestone Awaiting Review deleted

Thanks for the follow-up!

Note: See TracTickets for help on using tickets.