Skip to content

Commit

Permalink
fix: sanitise and escape the pretty option (#3314)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForbesLindesay authored Feb 28, 2021
1 parent 06baa52 commit 991e78f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/pug-code-gen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ function Compiler(node, options) {
if (this.pp && typeof this.pp !== 'string') {
this.pp = ' ';
}
if (this.pp && !/^\s+$/.test(this.pp)) {
throw new Error(
'The pretty parameter should either be a boolean or whitespace only string'
);
}
this.debug = false !== options.compileDebug;
this.indents = 0;
this.parentIndents = 0;
Expand Down Expand Up @@ -452,7 +457,9 @@ Compiler.prototype = {
visitMixinBlock: function(block) {
if (this.pp)
this.buf.push(
"pug_indent.push('" + Array(this.indents + 1).join(this.pp) + "');"
'pug_indent.push(' +
stringify(Array(this.indents + 1).join(this.pp)) +
');'
);
this.buf.push('block && block();');
if (this.pp) this.buf.push('pug_indent.pop();');
Expand Down Expand Up @@ -504,7 +511,9 @@ Compiler.prototype = {
this.mixins[key].used = true;
if (pp)
this.buf.push(
"pug_indent.push('" + Array(this.indents + 1).join(pp) + "');"
'pug_indent.push(' +
stringify(Array(this.indents + 1).join(pp)) +
');'
);
if (block || attrs.length || attrsBlocks.length) {
this.buf.push(name + '.call({');
Expand Down

0 comments on commit 991e78f

Please sign in to comment.