Skip to content

Function addQueryArgs in @wordpress/url should add query args before URL fragment #16655

@davilera

Description

@davilera

Function addQueryArgs adds query args in the incorrect place when the URL contains a URL fragment. According to RFC 3986, query args come before the URL fragment:

relative-ref = relative-part [ "?" query ] [ "#" fragment ]

Therefore, when invoking addQueryArgs as follows:

wp.url.addQueryArgs( 'https://example.com/page/#fragment', { param: 'value' } )

the expected result is:

https://example.com/page/?param=value#fragment

but the invalid result we get is:

https://example.com/page/#fragment?param=value

Additional context

  • Tested with Gutenberg 6.1.1.

Metadata

Metadata

Assignees

Labels

[Package] Url/packages/url[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions