Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Use regex for BOM, always strip. #46, #18
Browse files Browse the repository at this point in the history
  • Loading branch information
kirbysayshi committed Oct 12, 2015
1 parent 76bace1 commit 3d0d271
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@ function hbsfy(file, opts) {
var compiled = "// hbsfy compiled Handlebars template\n";
var parsed = null;
var partials = null;

if (opts && (opts.b || opts.bom) && buffer.indexOf('') === 0) {
buffer = buffer.substring(1);
}

// Kill BOM
buffer = buffer.replace(/^\uFEFF/, '');

try {
if (traverse) {
Expand Down
14 changes: 6 additions & 8 deletions test/bom_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@
var assert = require("assert");
var concat = require("concat-stream");
var fs = require("fs");
var hbsfyBom = require("hbsfy");
var hbsfyNoBom = require("hbsfy").configure({
bom: true
});
var hbsfy = require("hbsfy");

var templatePath = __dirname + "/bom.hbs";
var reBOM = /^\uFEFF/;

// Ensure our fixture actually contains a BOM
fs.createReadStream(templatePath)
.pipe(hbsfyBom(templatePath))
.pipe(concat(function(data) {
assert(
//.test(data.toString()),
reBOM.test(data.toString()),
"The template should contain a bom"
);
}));

fs.createReadStream(templatePath)
.pipe(hbsfyNoBom(templatePath))
.pipe(hbsfy(templatePath))
.pipe(concat(function(data) {
assert(
//.test(data.toString()) === false,
reBOM.test(data.toString()) === false,
"The template should not contain a bom"
);
}));

0 comments on commit 3d0d271

Please sign in to comment.