From a653b8af552dcb9e4f137fa82209f9cd1fa8938e Mon Sep 17 00:00:00 2001 From: e2tha-e Date: Sun, 31 Jul 2016 12:45:02 -0400 Subject: [PATCH 1/4] findPartial finds partials with parameters with newlines --- lib/util_mustache.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/util_mustache.js b/lib/util_mustache.js index b88f3da..588766e 100644 --- a/lib/util_mustache.js +++ b/lib/util_mustache.js @@ -12,8 +12,26 @@ // the term "alphanumeric" includes underscores. -// todo: document this exact regex long form. -var partialsRE = new RegExp(/{{>\s*?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_|]+)?(?:(?:| )\(.*)?(?:\s*)?}}/g); +// look for an opening mustache include tag, followed by >=0 whitespaces +var partialsStr = '{{>\\s*'; + +// one or more characters comprising any combination of alphanumerics, +// hyphens, periods, slashses, and tildes +partialsStr += '([\\w\\-\\.\\/~]+)'; + +// an optional group comprising a colon followed by one or more characters +// comprising any combination of alphanumerics, +// hyphens, and pipes +partialsStr += '(\\:[\\w\\-\\|]+)?'; + +// a group of characters starting with >=0 whitespaces, followed by an opening +// parenthesis, followed by any number of characters that are not closing +// parentheses, followed by a closing parenthesis +partialsStr += '(\\s*\\([^\\)]*\\))?'; + +// look for >=0 whitespaces, followed by closing mustache tag +partialsStr += '\\s*}}'; +var partialsRE = new RegExp(partialsStr, 'g'); // look for an opening mustache include tag, followed by >=0 whitespaces var partialsWithStyleModifiersStr = '{{>\\s*'; From bd9e1bce5b2d6c00b11171ff8061adf5e8a7b2ce Mon Sep 17 00:00:00 2001 From: e2tha-e Date: Sun, 31 Jul 2016 19:00:45 -0400 Subject: [PATCH 2/4] stronger regexes for partial parameters --- lib/util_mustache.js | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/util_mustache.js b/lib/util_mustache.js index 588766e..00a892e 100644 --- a/lib/util_mustache.js +++ b/lib/util_mustache.js @@ -20,14 +20,13 @@ var partialsStr = '{{>\\s*'; partialsStr += '([\\w\\-\\.\\/~]+)'; // an optional group comprising a colon followed by one or more characters -// comprising any combination of alphanumerics, -// hyphens, and pipes +// comprising any combination of alphanumerics, hyphens, and pipes partialsStr += '(\\:[\\w\\-\\|]+)?'; -// a group of characters starting with >=0 whitespaces, followed by an opening -// parenthesis, followed by any number of characters that are not closing -// parentheses, followed by a closing parenthesis -partialsStr += '(\\s*\\([^\\)]*\\))?'; +// a optional group of characters starting with >=0 whitespaces, followed by an +// opening parenthesis, followed by a lazy match of non-whitespace or whitespace +// characters (to include newlines), followed by a closing parenthesis +partialsStr += '(\\s*\\([\\S\\s]*?\\))?'; // look for >=0 whitespaces, followed by closing mustache tag partialsStr += '\\s*}}'; @@ -47,10 +46,10 @@ partialsWithStyleModifiersStr += '(?!\\()'; // of alphanumerics, hyphens, and pipes partialsWithStyleModifiersStr += '(\\:[\\w\\-\\|]+)'; -// an optional group of characters starting with >=0 whitespaces, followed by -// an opening parenthesis, followed by any number of characters that are not -// closing parentheses, followed by a closing parenthesis -partialsWithStyleModifiersStr += '(\\s*\\([^\\)]*\\))?'; +// a optional group of characters starting with >=0 whitespaces, followed by an +// opening parenthesis, followed by a lazy match of non-whitespace or whitespace +// characters (to include newlines), followed by a closing parenthesis +partialsWithStyleModifiersStr += '(\\s*\\([\\S\\s]*?\\))?'; // look for >=0 whitespaces, followed by closing mustache tag partialsWithStyleModifiersStr += '\\s*}}'; @@ -64,14 +63,13 @@ var partialsWithPatternParametersStr = '{{>\\s*'; partialsWithPatternParametersStr += '([\\w\\-\\.\\/~]+)'; // an optional group comprising a colon followed by one or more characters -// comprising any combination of alphanumerics, -// hyphens, and pipes +// comprising any combination of alphanumerics, hyphens, and pipes partialsWithPatternParametersStr += '(\\:[\\w\\-\\|]+)?'; -// a group of characters starting with >=0 whitespaces, followed by an opening -// parenthesis, followed by any number of characters that are not closing -// parentheses, followed by a closing parenthesis -partialsWithPatternParametersStr += '(\\s*\\([^\\)]*\\))'; +// a group of characters starting with >=0 whitespaces, followed by an +// opening parenthesis, followed by a lazy match of non-whitespace or whitespace +// characters (to include newlines), followed by a closing parenthesis +partialsWithPatternParametersStr += '(\\s*\\([\\S\\s)]*?\\))'; // look for >=0 whitespaces, followed by closing mustache tag partialsWithPatternParametersStr += '\\s*}}'; @@ -118,8 +116,7 @@ var utilMustache = { partialsRE: partialsRE, partialsWithStyleModifiersRE: partialsWithStyleModifiersRE, partialsWithPatternParametersRE: partialsWithPatternParametersRE, - listItemsRE: listItemsRE, - partialKeyRE: partialKeyRE + listItemsRE: listItemsRE }; module.exports = utilMustache; From c68832a2bcd06393062bf701b50983362d2f0554 Mon Sep 17 00:00:00 2001 From: e2tha-e Date: Mon, 1 Aug 2016 13:44:40 -0400 Subject: [PATCH 3/4] comment grammar fix --- lib/util_mustache.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/util_mustache.js b/lib/util_mustache.js index 00a892e..99b300a 100644 --- a/lib/util_mustache.js +++ b/lib/util_mustache.js @@ -23,7 +23,7 @@ partialsStr += '([\\w\\-\\.\\/~]+)'; // comprising any combination of alphanumerics, hyphens, and pipes partialsStr += '(\\:[\\w\\-\\|]+)?'; -// a optional group of characters starting with >=0 whitespaces, followed by an +// an optional group of characters starting with >=0 whitespaces, followed by an // opening parenthesis, followed by a lazy match of non-whitespace or whitespace // characters (to include newlines), followed by a closing parenthesis partialsStr += '(\\s*\\([\\S\\s]*?\\))?'; @@ -46,7 +46,7 @@ partialsWithStyleModifiersStr += '(?!\\()'; // of alphanumerics, hyphens, and pipes partialsWithStyleModifiersStr += '(\\:[\\w\\-\\|]+)'; -// a optional group of characters starting with >=0 whitespaces, followed by an +// an optional group of characters starting with >=0 whitespaces, followed by an // opening parenthesis, followed by a lazy match of non-whitespace or whitespace // characters (to include newlines), followed by a closing parenthesis partialsWithStyleModifiersStr += '(\\s*\\([\\S\\s]*?\\))?'; From 98f414cb8974ff6a04cc4928b52d1f5bf39de73d Mon Sep 17 00:00:00 2001 From: e2tha-e Date: Mon, 1 Aug 2016 13:48:53 -0400 Subject: [PATCH 4/4] deleting redundant and unused partialKeyRE --- lib/util_mustache.js | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/lib/util_mustache.js b/lib/util_mustache.js index 99b300a..26b05e7 100644 --- a/lib/util_mustache.js +++ b/lib/util_mustache.js @@ -88,30 +88,6 @@ listItemsStr += '(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve listItemsStr += '\\s*}}'; var listItemsRE = new RegExp(listItemsStr, 'g'); -// look for an opening mustache loop tag, followed by >=0 whitespaces -var partialKeyStr = '{{>\\s*'; - -// one or more characters comprising any combination of alphanumerics, -// hyphens, periods, slashses, and tildes -partialKeyStr += '([\\w\\-\\.\\/~]+)'; - -// an optional group of characters starting with a colon, followed by >0 -// alphanumerics, hyphens, or pipes -partialKeyStr += '(\\:[\\w\\-|]+)?'; - -// an optional group of characters starting with a colon, followed by >0 -// alphanumerics or hyphens -partialKeyStr += '(\\:[\\w\\-]+)?'; - -// an optional group of characters starting with >=0 whitespaces, followed by -// an opening parenthesis, followed by any number of characters that are not -// closing parentheses, followed by a closing parenthesis -partialKeyStr += '(\\s*\\([^\\)]*\\))?'; - -// look for >=0 whitespaces, followed by closing mustache tag -partialKeyStr += '\\s*}}'; -var partialKeyRE = new RegExp(partialKeyStr, 'g'); - var utilMustache = { partialsRE: partialsRE, partialsWithStyleModifiersRE: partialsWithStyleModifiersRE,