Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow hypen prefix in substitutions #17

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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