Comparing version 0.2.0 to 0.3.0
@@ -61,6 +61,6 @@ | ||
interpolate.apply(this); | ||
return this._handleIf(attributes); | ||
return this._handleIf(attributes, variables); | ||
case "elif": | ||
interpolate.apply(this); | ||
return this._handleElseIf(attributes); | ||
return this._handleElseIf(attributes, variables); | ||
case "else": | ||
@@ -203,12 +203,6 @@ interpolate.apply(this); | ||
_handleIf: function(attributes) { | ||
_handleIf: function(attributes, variables) { | ||
this.conditionals = []; | ||
if (attributes.length === 1 && attributes[0].name === "expr") { | ||
// Create a new conditional, put it on the stack and assign as current conditional | ||
var conditional = new Conditional(attributes[0].value); | ||
this.conditionals.push(conditional); | ||
this.currentConditional = conditional; | ||
return {output: ""}; | ||
return this._handleExpr(attributes[0].value, variables); | ||
} | ||
@@ -219,3 +213,3 @@ | ||
_handleElseIf: function(attributes) { | ||
_handleElseIf: function(attributes, variables) { | ||
if (attributes.length === 1 && attributes[0].name === "expr") { | ||
@@ -225,8 +219,3 @@ if (!this._inConditional()) { | ||
} | ||
var conditional = new Conditional(attributes[0].value); | ||
this.conditionals.push(conditional); | ||
this.currentConditional = conditional; | ||
return {output: ""}; | ||
return this._handleExpr(attributes[0].value, variables); | ||
} | ||
@@ -243,7 +232,3 @@ | ||
// As a hack, just provide an always true expression | ||
var conditional = new Conditional("true"); | ||
this.conditionals.push(conditional); | ||
this.currentConditional = conditional; | ||
return {output: ""}; | ||
return this._handleExpr("true"); | ||
}, | ||
@@ -290,2 +275,21 @@ | ||
_handleExpr: function(expression, variables) { | ||
// HACK for Regex variable support | ||
if (expression.split(' ').length == 3) var statement = expression.split(' '); | ||
if (statement) { | ||
var variable = variables[statement[0].substring(1)]; | ||
var regex = new RegExp(/^\/(.*)\/$/.test(statement[2]) ? statement[2].slice(1, -1).replace(/\\\\/g, "\\") : statement[2]); | ||
var result = regex.exec(variable); | ||
expression = (statement[1] == '!=' ? !!!result : !!result).toString(); | ||
result && result.forEach(function(val, index){ | ||
variables[index.toString()] = val; | ||
}); | ||
} | ||
// Create a new conditional, put it on the stack and assign as current conditional | ||
var conditional = new Conditional(expression); | ||
this.conditionals.push(conditional); | ||
this.currentConditional = conditional; | ||
return {output: ""}; | ||
}, | ||
_isConditional: function(directive) { | ||
@@ -292,0 +296,0 @@ return (directive === "if" || directive === "elif" || directive === "else" || directive === "endif"); |
{ | ||
"name": "ssi", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Server Side Includes for NodeJS", | ||
@@ -5,0 +5,0 @@ "author": "Chen-Heng Chang <wandererm@gmail.com> (http://kidwm.net/)", |
@@ -61,2 +61,13 @@ | ||
}); | ||
it("regular expression variable capture", function() { | ||
var conditional = "<!--#set var=\"date\" value=\"2016-01-01\" -->"; | ||
conditional += "<!--#if expr=\"$date = /(\\d+)-0?(\\d+)-0?(\\d+)/\" -->"; | ||
conditional += "<!--#endif -->"; | ||
var results = parser.parse("", conditional); | ||
assert.deepEqual('2016', results.variables['1']); | ||
assert.deepEqual('1', results.variables['2']); | ||
assert.deepEqual('1', results.variables['3']); | ||
}); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
28179
631
1