From a0ea69672145a4bfcd1eafc5cb17c94bfa2d9059 Mon Sep 17 00:00:00 2001 From: Jordan Rastrick Date: Wed, 9 May 2018 17:28:14 +1000 Subject: [PATCH 1/2] fix(comment-escaping): Escape comment delimiters in `req.path` and occuring multiply Currently a req.path containing */ (* is a valid URL character) will on recording terminate the headers' comment, leaving a broken tape. Similarly if a /* or */ occurs more than once the additional sequences are not escaped. --- src/tape.ejs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/tape.ejs b/src/tape.ejs index 58ed46d..c39f77f 100644 --- a/src/tape.ejs +++ b/src/tape.ejs @@ -1,10 +1,14 @@ var path = require("path"); +<% function escapeComments(str) { + return str.split('/*').join('/ *').split('*/').join('* /') +} %> + /** - * <%- req.method %> <%- decodeURIComponent(req.path) %> + * <%- req.method %> <%- escapeComments(decodeURIComponent(req.path)) %> * <% Object.keys(req._headers).forEach(function (key) { -%> - * <%- key %>: <%- req._headers[key].replace('/*', '/ *').replace('*/', '* /') %> + * <%- key %>: <%- escapeComments(req._headers[key]) %> <% }); -%> */ From 5e822b6271c8f27e51fa6855cc1a4a9c26b8e5ce Mon Sep 17 00:00:00 2001 From: Jordan Rastrick Date: Thu, 10 May 2018 13:39:14 +1000 Subject: [PATCH 2/2] fix(comment-escaping): Make ejs whitespace match tests --- src/tape.ejs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/tape.ejs b/src/tape.ejs index c39f77f..b75f10c 100644 --- a/src/tape.ejs +++ b/src/tape.ejs @@ -1,8 +1,7 @@ -var path = require("path"); - -<% function escapeComments(str) { +<%_ function escapeComments(str) { return str.split('/*').join('/ *').split('*/').join('* /') -} %> +} _%> +var path = require("path"); /** * <%- req.method %> <%- escapeComments(decodeURIComponent(req.path)) %>