Opened 6 weeks ago
Closed 4 weeks ago
#64372 closed defect (bug) (fixed)
Additional URL args supplied via enqueued script/style handle cause malformed ver query param when null
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | low |
| Severity: | normal | Version: | 2.6 |
| Component: | Script Loader | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description (last modified by )
When working on fixing PHPStan issues (#64238) for WP_Scripts (r61358), I stumbled across a capability I was previously unaware of: you can pass additional query parameters to an enqueued script/style URL by adding them to the handle. For example:
<?php wp_enqueue_script( 'foo?bar=baz&baz=quux', 'https://example.com/test.js', array(), '1.0' );
This results in the following script being printed:
<script type="text/javascript" src="https://example.com/test.js?ver=1.0&bar=baz&baz=quux" id="foo-js"></script
This capability is not included in any unit test, and it may be a vestige of something no longer used. Naturally, a better way to do this now would seem to be to leverage the script_loader_src filter, or rather, to add the query parameters to the URL being registered in the first place. I can find one plugin (Map Navigator) which seems to be using this intentionally.
In any case, I found that this capability is broken when using null as a version:
<?php wp_enqueue_script( 'foo?bar=baz&baz=quux', 'https://example.com/test.js', array(), null );
This results in:
<script type="text/javascript" src="https://example.com/test.js?ver=bar=baz&baz=quux" id="foo-js"></script>
Note the query string: ver=bar=baz&baz=quux.
The "ver=" shouldn't have been included here.
Change History (5)
This ticket was mentioned in PR #10608 on WordPress/wordpress-develop by @westonruter.
6 weeks ago
#1
- Keywords has-patch has-unit-tests added
@westonruter commented on PR #10608:
5 weeks ago
#4
@peterwilsoncc I added your example code as a test case in 624ea26959281a29bbb0f4f475dc3b4b49521ee2.
I then added ba88780 to ensure this PR outputs the same markup, except for what is supposed to be fixed of course.
Trac ticket: https://core.trac.wordpress.org/ticket/64372
This pull request was based off of https://github.com/WordPress/wordpress-develop/pull/10607