Skip to content

Commit

Permalink
Merge pull request #17 from evanshortiss/fix-url-hyphen-substitution
Browse files Browse the repository at this point in the history
allow hypen prefix in substitutions
  • Loading branch information
evanshortiss authored May 11, 2023
2 parents e3cddb8 + a6280dc commit 3260771
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions preview-src/index-username.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is an empty page used to help verify the parameter replacement in content containing leading hyphens, i.e `%NAME%` should be replaced in both `hello-%NAME%` and `hello %NAME%`.
4 changes: 4 additions & 0 deletions preview-src/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ I like %COLOR% color

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

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.

This link should substitute the `USER` queryparam into the URL itself: link:index-%USER%.html?USER=%USER%#link-testing[index-%USER%.html^]

[#query-string-replacement-testing]
== Query String Replacement Testing

Expand Down
10 changes: 8 additions & 2 deletions src/js/07-userparams-behaviour.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ document.addEventListener('DOMContentLoaded', function () {

function applyPattern (str, key, value) {
//(%25key%25|%key%) %25 is urlencode value of %
var pattern = '(' + '%25' + key + '%25' +
'|(?<!-)' + '%' + key + '%' + '(?!-))'
var pattern = '(' + '%25' + key + '%25' + '|' + '%' + key + '%' + ')'

// The following pattern was introduced in commit db18c1dca8e101d0f3a2e512c43ada19168e5afe,
// but it's not clear why the negative lookbehind was added. Keeping here
// in case we need a revert in the future
// var pattern = '(' + '%25' + key + '%25' +
// '|(?<!-)' + '%' + key + '%' + '(?!-))'

var re = new RegExp(pattern, 'gi')
return str.replace(re, value)
}
Expand Down

0 comments on commit 3260771

Please sign in to comment.