broccoli-sri-hash
Advanced tools
Comparing version
@@ -0,1 +1,7 @@ | ||
# 1.0.1 | ||
- Changed code to work with 0.2.x broccoli-filter | ||
- Made stateless checks be global to remove recalculation | ||
- Adding in more failure tests for broken HTML | ||
- Cleaning up regex to cope with failure cases | ||
# 1.0.0 | ||
@@ -2,0 +8,0 @@ - Added in build steps and badges |
26
index.js
@@ -5,6 +5,9 @@ var Filter = require('broccoli-filter'); | ||
var crypto = require('crypto'); | ||
var styleCheck = /\srel=["\'][^"]*stylesheet[^"]*["\']/; | ||
var srcCheck = /\ssrc=["\']([^"\']+)["\']/; | ||
var hrefCheck = /\shref=["\']([^"\']+)["\']/; | ||
function SRIHashAssets(inputTree, options) { | ||
function SRIHashAssets(inputNode, options) { | ||
if (!(this instanceof SRIHashAssets)) { | ||
return new SRIHashAssets(inputTree, options); | ||
return new SRIHashAssets(inputNode, options); | ||
} | ||
@@ -14,3 +17,3 @@ | ||
this.context = this.options.context || {}; | ||
this.inputTree = inputTree; | ||
Filter.call(this, inputNode); | ||
@@ -36,10 +39,13 @@ if ('origin' in this.options) { | ||
var linkCheck = new RegExp('<link[^>]*href=["\']([^"]*)["\'][^>]*>', 'g'); | ||
var styleCheck = new RegExp('rel=["\'][^"]*stylesheet[^"]*["\']'); | ||
var srcCheck = new RegExp('src=["\']([^"\']+)["\']'); | ||
var hrefCheck = new RegExp('href=["\']([^"\']+)["\']'); | ||
return string.replace(scriptCheck, function srcMatch(match) { | ||
var src = match.match(srcCheck); | ||
var filePath = src[1]; | ||
var filePath; | ||
if (!src) { | ||
return match; | ||
} | ||
filePath = src[1]; | ||
return that.mungeOutput(match, filePath, file); | ||
@@ -49,9 +55,11 @@ }).replace(linkCheck, function hrefMatch(match) { | ||
var isStyle = styleCheck.test(match); | ||
var filePath = href[1]; | ||
var filePath; | ||
if (!isStyle) { | ||
if (!isStyle || !href) { | ||
return match; | ||
} | ||
filePath = href[1]; | ||
return that.mungeOutput(match, filePath, file); | ||
@@ -58,0 +66,0 @@ }); |
{ | ||
"name": "broccoli-sri-hash", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Generates SRI hashes for html files", | ||
@@ -22,2 +22,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"broccoli-filter": "^0.2.0", | ||
"chai": "^3.0.0", | ||
@@ -24,0 +25,0 @@ "eslint-config-nightmare-mode": "0.1.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
19133
50.43%20
5.26%154
3.36%4
33.33%