Socket
Socket
Sign inDemoInstall

ssi

Package Overview
Dependencies
6
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.4 to 0.1.5

test/html/config.shtml

17

lib/DirectiveHandler.js

@@ -79,3 +79,3 @@

interpolate.apply(this);
return this._handleInclude(attributes, currentFile);
return this._handleInclude(attributes, currentFile, variables);
}

@@ -167,3 +167,3 @@

_handleInclude: function(attributes, currentFile) {
_handleInclude: function(attributes, currentFile, variables) {
if (attributes.length !== 1) {

@@ -187,5 +187,16 @@ return {error: "Directive #include did not contain the correct number of attributes"};

// Parse the contents of the file to handle SSI directives
var parsed = this.parser.parse(this.ioUtils.resolveFullPath(currentFile, filename), results.output);
var parsed = this.parser.parse(this.ioUtils.resolveFullPath(currentFile, filename), results.output, variables);
results.output = parsed.contents;
results.variables = [];
for (var key in parsed.variables) {
if (parsed.variables.hasOwnProperty(key)) {
results.variables.push({
name: key,
value: parsed.variables[key]
});
}
}
return results;

@@ -192,0 +203,0 @@ },

4

lib/SSI.js

@@ -39,5 +39,5 @@

parse: function(filename, contents) {
parse: function(filename, contents, variables) {
var instance = this;
var variables = {};
variables = variables || {};

@@ -44,0 +44,0 @@ contents = contents.replace(new RegExp(DIRECTIVE_MATCHER), function(directive, directiveName) {

{
"name": "ssi",
"version": "0.1.4",
"version": "0.1.5",
"description": "Server Side Includes for NodeJS",

@@ -5,0 +5,0 @@ "author": "Glenn Nelson <glenn@hexcoder.us> (glenn@hexcoder.us)",

@@ -16,2 +16,3 @@ node-ssi

<!--#set var="" value="" -->
<!--#echo var="" -->

@@ -18,0 +19,0 @@ <!--#if expr="" -->

@@ -17,3 +17,42 @@

});
it("should include variables defined in included files", function() {
var filename = "test/html/include-vars.shtml";
var contents = fs.readFileSync(filename, {encoding: "utf8"});
var results = parser.parse(filename, contents);
assert.equal("FIRST", results.variables["FIRST_VAR"]);
assert.equal("SECOND", results.variables["SECOND_VAR"]);
assert.equal("\nFIRSTSECOND\n", results.contents);
});
it("should include variables in order of import", function() {
var filename = "test/html/include-vars-order.shtml";
var contents = fs.readFileSync(filename, {encoding: "utf8"});
var results = parser.parse(filename, contents);
assert.equal("FIRST", results.variables["FIRST"]);
assert.equal("SECOND", results.variables["SECOND"]);
assert.equal("OVERRIDDEN", results.variables["OVERRIDE"]);
assert.equal("I DO!!", results.variables["EXISTS"]);
assert.equal("\nFIRSTSECONDFUCK!!\n\nFIRSTSECONDOVERRIDDENI DO!!", results.contents);
});
it("should include nested variables", function() {
var filename = "test/html/include-var-nested.shtml";
var contents = fs.readFileSync(filename, {encoding: "utf8"});
var results = parser.parse(filename, contents);
assert.equal("NESTED!!", results.variables["NESTED"]);
assert.equal("NESTED!!", results.contents);
});
it("should pass variables down into included files", function() {
var filename = "test/html/include-root.shtml";
var contents = fs.readFileSync(filename, {encoding: "utf8"});
var results = parser.parse(filename, contents);
assert.equal("Hallo, Welt! This should be included!", results.contents);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc