From 6a3705b048112990bbd4f7666d747d7c107dd0b7 Mon Sep 17 00:00:00 2001 From: Mo Langning <133737702+molangning@users.noreply.github.com> Date: Mon, 26 Feb 2024 03:31:19 +0000 Subject: [PATCH 1/3] Fix bugs --- packages/pug-code-gen/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/pug-code-gen/index.js b/packages/pug-code-gen/index.js index de5c70a72..75f7fa854 100644 --- a/packages/pug-code-gen/index.js +++ b/packages/pug-code-gen/index.js @@ -69,6 +69,11 @@ function Compiler(node, options) { this.mixins = {}; this.dynamicMixins = false; this.eachCount = 0; + if (options.templateName && !/^[0-9a-zA-Z\-\_]+?$/.test(options.templateName)) { + throw new Error( + 'Template name should be a valid function name' + ); + } if (options.doctype) this.setDoctype(options.doctype); this.runtimeFunctionsUsed = []; this.inlineRuntimeFunctions = options.inlineRuntimeFunctions || false; @@ -311,10 +316,17 @@ Compiler.prototype = { } if (debug && node.debug !== false && node.type !== 'Block') { + if (typeof node.line !== 'number'){ + throw new Error( + 'node.line is not a valid number. Possible prototype polution?' + ); + } + if (node.line) { var js = ';pug_debug_line = ' + node.line; - if (node.filename) + if (node.filename){ js += ';pug_debug_filename = ' + stringify(node.filename); + } this.buf.push(js + ';'); } } From beb686e33ed7ead91222cf78025f3f2eaab238a5 Mon Sep 17 00:00:00 2001 From: Mo Langning <133737702+molangning@users.noreply.github.com> Date: Mon, 26 Feb 2024 20:00:20 +0800 Subject: [PATCH 2/3] reformat --- packages/pug-code-gen/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pug-code-gen/index.js b/packages/pug-code-gen/index.js index 75f7fa854..dec1bb427 100644 --- a/packages/pug-code-gen/index.js +++ b/packages/pug-code-gen/index.js @@ -316,7 +316,7 @@ Compiler.prototype = { } if (debug && node.debug !== false && node.type !== 'Block') { - if (typeof node.line !== 'number'){ + if (typeof node.line !== 'number') { throw new Error( 'node.line is not a valid number. Possible prototype polution?' ); From b720344dad7c5a011ce42492f7de6ed08919c712 Mon Sep 17 00:00:00 2001 From: Mo Langning <133737702+molangning@users.noreply.github.com> Date: Mon, 26 Feb 2024 20:02:09 +0800 Subject: [PATCH 3/3] Deleted extra line --- packages/pug-code-gen/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pug-code-gen/index.js b/packages/pug-code-gen/index.js index dec1bb427..a6b63f899 100644 --- a/packages/pug-code-gen/index.js +++ b/packages/pug-code-gen/index.js @@ -318,7 +318,7 @@ Compiler.prototype = { if (debug && node.debug !== false && node.type !== 'Block') { if (typeof node.line !== 'number') { throw new Error( - 'node.line is not a valid number. Possible prototype polution?' + 'node.line is not a valid number.' ); }