Appending a Query Parameter with a default value to the href in links does not work
What's the issue?
We are trying to use variable substitution in links as documented here and here.
Here is an example of the HTML we are using:
<a href="//example.com/" data-amp-addparams="SRC=QUERY_PARAM(SRC,XXXX)" data-amp-replace="QUERY_PARAM">Go to my site</a>
Clicking on the above link we get //example.com/?SRC=(SRC,XXXX) instead of linking to //example.com/?SRC=XXXX
There is nowhere that explicitly states in the AMP documentation that using QUERY_PARAM with a default value in combination with data-amp-addparams will give the desired outcome. However, there is nowhere explicitly stating that it will not. If there is a valid reason for why this can't be done it may be best to highlight this in the docs.
How do we reproduce the issue?
Here is a link to the test case - http://jsbin.com/pesevax/edit?html,output
4 scenarios are outlined in the jsbin with the final scenario highlighting the issue.
What browsers are affected?
Seems to affect all browsers. We have observed this behaviour in Chrome, Safari, Firefox and Microsoft Edge.
Which AMP version is affected?
Version 1524089272632 but I believe this was always an issue.
CC: @jridgewell
This is coming from https://github.com/ampproject/amphtml/blob/master/src/service/url-replacements-impl.js#L951.
// All good here
const params = parseQueryString(additionalUrlParameters); // => { 'SRC': 'QUERY_PARAM(SRC,XXXX)' }
// Ugh, encoding.
addParamsToUrl('//example.com/', params); // => '//example.com/?SRC=QUERY_PARAM(SRC%2CXXXX)'
/cc @Gregable, can you think of any security issues with just plain concating the data-amp-addparams to the href?
It should be fine, because the user can do whatever in anchor href in anyway. Runtime should just do a plain concat.
This issue hasn't been updated in awhile. @lannka Do you have any updates?
This issue hasn't been updated in awhile. @lannka Do you have any updates?