Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nodesi

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodesi - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

52

lib/esi.js

@@ -34,3 +34,3 @@ /* jshint node:true */

self.findESITags(html, options).forEach(function(tag) {
self.findESIInclueTags(html, options).forEach(function(tag) {
var placeholder = '<!-- esi-placeholder-' + i + ' -->';

@@ -73,17 +73,26 @@

ESI.prototype.findESITags = function(html) {
var OPEN = '<esi:',
CLOSE = '</esi:include>',
ESI.prototype.findESIInclueTags = function(html) {
var open = '<esi:include',
fullClose = '</esi:include>',
selfClose = '/>',
tags = [],
nextTagOpen,
nextTagClose,
nextTagFullClose,
nextTagSelfClose,
reducedHtml = html;
do {
nextTagOpen = reducedHtml.indexOf(OPEN);
nextTagOpen = reducedHtml.indexOf(open);
if(nextTagOpen > -1) {
reducedHtml = reducedHtml.substr(nextTagOpen);
nextTagClose = reducedHtml.indexOf(CLOSE);
tags.push(reducedHtml.substr(0, nextTagClose + CLOSE.length));
reducedHtml = reducedHtml.substr(nextTagClose + CLOSE.length);
nextTagFullClose = reducedHtml.indexOf(fullClose);
nextTagSelfClose = reducedHtml.indexOf(selfClose);
if(nextTagFullClose > nextTagSelfClose) {
tags.push(reducedHtml.substr(0, nextTagFullClose + fullClose.length));
reducedHtml = reducedHtml.substr(nextTagFullClose + fullClose.length);
} else {
tags.push(reducedHtml.substr(0, nextTagSelfClose + selfClose.length));
reducedHtml = reducedHtml.substr(nextTagSelfClose + selfClose.length);
}
}

@@ -97,3 +106,3 @@ } while(nextTagOpen > -1);

var self = this,
src = self.getIncludeSrc(tag);
src = self.getDoubleQuotedSrc(tag) || self.getSingleQuotedSrc(tag) || self.getUnquotedSrc(tag);

@@ -103,12 +112,21 @@ return self.get(src, options);

ESI.prototype.getIncludeSrc = function(tag) {
var OPEN = 'src="',
CLOSE = '"',
srcOpen = tag.indexOf(OPEN),
tagFragment = tag.substr(srcOpen + OPEN.length),
srcClose = tagFragment.indexOf(CLOSE);
ESI.prototype.getBoundedString = function(open, close) {
return function(str) {
var before = str.indexOf(open),
strFragment,
after;
return tagFragment.substr(0, srcClose);
if(before > -1) {
strFragment = str.substr(before + open.length);
after = strFragment.indexOf(close);
return strFragment.substr(0, after);
}
return '';
};
};
ESI.prototype.getDoubleQuotedSrc = ESI.prototype.getBoundedString('src="', '"');
ESI.prototype.getSingleQuotedSrc = ESI.prototype.getBoundedString("src='", "'");
ESI.prototype.getUnquotedSrc = ESI.prototype.getBoundedString('src=', '>');
ESI.prototype.get = function (src, options) {

@@ -115,0 +133,0 @@ var self = this;

{
"name": "nodesi",
"version": "1.0.5",
"version": "1.0.6",
"description": "ESI: the good parts in node.js",

@@ -5,0 +5,0 @@ "main": "esi.js",

@@ -55,2 +55,65 @@ /* jshint node:true */

it('should fetch one external component with single quoted src', function (done) {
// given
server.addListener('request', function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<div>test</div>');
});
var html = "<section><esi:include src='http://localhost:" + port + "'></esi:include></section>";
// when
var processed = new ESI().process(html);
// then
processed.then(function (response) {
assert.equal(response, '<section><div>test</div></section>');
done();
}).catch(done);
});
it('should fetch one external component with unquoted src', function (done) {
// given
server.addListener('request', function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<div>test</div>');
});
var html = '<section><esi:include src=http://localhost:' + port + '></esi:include></section>';
// when
var processed = new ESI().process(html);
// then
processed.then(function (response) {
assert.equal(response, '<section><div>test</div></section>');
done();
}).catch(done);
});
it('should fetch one self-closed external component', function (done) {
// given
server.addListener('request', function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<div>test</div>');
});
var html = '<section><esi:include src="http://localhost:' + port + '"/></section>';
// when
var processed = new ESI().process(html);
// then
processed.then(function (response) {
assert.equal(response, '<section><div>test</div></section>');
done();
}).catch(done);
});
it('should fetch one relative component', function (done) {

@@ -57,0 +120,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc