option for URI decoded, but still html escaped urls
This commit is contained in:
parent
8d55d4910e
commit
4b19400634
|
@ -32,7 +32,8 @@ module.exports = app;
|
||||||
|
|
||||||
* This module will call `next()` if the connection is already tls / https.
|
* This module will call `next()` if the connection is already tls / https.
|
||||||
* If `trustProxy` is true, and `X-Forward-Proto` is https, `next()` will be called.
|
* If `trustProxy` is true, and `X-Forward-Proto` is https, `next()` will be called.
|
||||||
* If you use `{{URL}}` in the body text it will be replaced with the url
|
* If you use `{{URL}}` in the body text it will be replaced with a URI encoded and HTML escaped url (it'll look just like it is)
|
||||||
|
* If you use `{{HTML_URL}}` in the body text it will be replaced with a URI decoded and HTML escaped url (it'll look just like it would in Chrome's URL bar)
|
||||||
|
|
||||||
## Demo
|
## Demo
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ var port = process.argv[2] || 8080;
|
||||||
|
|
||||||
server.on('request', require('./')({
|
server.on('request', require('./')({
|
||||||
port: 8443
|
port: 8443
|
||||||
, body: '<a href="{{URL}}">{{URL}}</a>'
|
, body: 'Redirecting to <a href="{{URL}}">{{HTML_URL}}</a>'
|
||||||
, trustProxy: true // default is false
|
, trustProxy: true // default is false
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
1
index.js
1
index.js
|
@ -32,6 +32,7 @@ module.exports = function (opts) {
|
||||||
//var encodedLocation = encodeURI(newLocation);
|
//var encodedLocation = encodeURI(newLocation);
|
||||||
var escapedLocation = escapeHtml(newLocation);
|
var escapedLocation = escapeHtml(newLocation);
|
||||||
var body = opts.body
|
var body = opts.body
|
||||||
|
.replace(/{{\s*HTML_URL\s*}}/ig, escapeHtml(decodeURIComponent(newLocation)))
|
||||||
.replace(/{{\s*URL\s*}}/ig, escapedLocation)
|
.replace(/{{\s*URL\s*}}/ig, escapedLocation)
|
||||||
.replace(/{{\s*UNSAFE_URL\s*}}/ig, newLocation)
|
.replace(/{{\s*UNSAFE_URL\s*}}/ig, newLocation)
|
||||||
;
|
;
|
||||||
|
|
Loading…
Reference in New Issue