From 4b194006341ee93ea48a907b56f90a3022dafe50 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 7 Jul 2015 17:30:56 -0600 Subject: [PATCH] option for URI decoded, but still html escaped urls --- README.md | 3 ++- example.js | 2 +- index.js | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 524b5e3..7697a46 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,8 @@ module.exports = app; * 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 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 diff --git a/example.js b/example.js index 3d22765..239c018 100644 --- a/example.js +++ b/example.js @@ -6,7 +6,7 @@ var port = process.argv[2] || 8080; server.on('request', require('./')({ port: 8443 -, body: '{{URL}}' +, body: 'Redirecting to {{HTML_URL}}' , trustProxy: true // default is false })); diff --git a/index.js b/index.js index 4259b0b..961ab0d 100644 --- a/index.js +++ b/index.js @@ -32,6 +32,7 @@ module.exports = function (opts) { //var encodedLocation = encodeURI(newLocation); var escapedLocation = escapeHtml(newLocation); var body = opts.body + .replace(/{{\s*HTML_URL\s*}}/ig, escapeHtml(decodeURIComponent(newLocation))) .replace(/{{\s*URL\s*}}/ig, escapedLocation) .replace(/{{\s*UNSAFE_URL\s*}}/ig, newLocation) ;