Skip to content

Commit db28f0e

Browse files
committed
hyphenated params replacement
1 parent c77db92 commit db28f0e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

preview-src/index.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ I like %COLOR% color
3232

3333
Here is a link:index.html?USER=%USER%#liber-recusabo[link^] containing a query string item that should open to "Liber recusabo" in a new window
3434

35+
This link (link:index.html?USER=username#link-testing[index.html?USER=username]) that will set the `USER` querystring parameter to `username` and return to this section.
36+
37+
This link should substitute the `USER` queryparam into the URL itself: link:index-%USER%.html?USER=%USER%#link-testing[index-%USER%.html^]
38+
3539
[#query-string-replacement-testing]
3640
== Query String Replacement Testing
3741

src/js/07-userparams-behaviour.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,14 @@ document.addEventListener('DOMContentLoaded', function () {
7878

7979
function applyPattern (str, key, value) {
8080
//(%25key%25|%key%) %25 is urlencode value of %
81-
var pattern = '(' + '%25' + key + '%25' +
82-
'|(?<!-)' + '%' + key + '%' + '(?!-))'
81+
var pattern = '(' + '%25' + key + '%25' + '|' + '%' + key + '%' + ')'
82+
83+
// The following pattern was introduced in commit db18c1dca8e101d0f3a2e512c43ada19168e5afe,
84+
// but it's not clear why the negative lookbehind was added. Keeping here
85+
// in case we need a revert in the future
86+
// var pattern = '(' + '%25' + key + '%25' +
87+
// '|(?<!-)' + '%' + key + '%' + '(?!-))'
88+
8389
var re = new RegExp(pattern, 'gi')
8490
return str.replace(re, value)
8591
}

0 commit comments

Comments
 (0)