Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefixing unicode byte order marks are stripped from included files #62

Merged
merged 1 commit into from
May 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var fs = require('fs'),
es = require('event-stream'),
gutil = require('gulp-util'),
glob = require('glob'),
applySourceMap = require('vinyl-sourcemaps-apply');
applySourceMap = require('vinyl-sourcemaps-apply'),
stripBom = require('strip-bom');

var SourceMapGenerator = require('source-map').SourceMapGenerator;
var SourceMapConsumer = require('source-map').SourceMapConsumer;
Expand Down Expand Up @@ -134,7 +135,8 @@ function processInclude(content, filePath, sourceMap) {
if (!inExtensions(globbedFilePath)) continue;

// Get file contents and apply recursive include on result
var fileContents = fs.readFileSync(globbedFilePath);
// Unicode byte order marks are stripped from the start of included files
var fileContents = stripBom(fs.readFileSync(globbedFilePath));

var result = processInclude(fileContents.toString(), globbedFilePath, sourceMap);
var resultContent = result.content;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"glob": "^5.0.12",
"gulp-util": "~2.2.10",
"source-map": "^0.5.1",
"strip-bom": "^2.0.0",
"vinyl-sourcemaps-apply": "^0.2.0"
}
}
10 changes: 10 additions & 0 deletions test/expected/html/basic-include-output-with-unicode-BOM.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<div>This is a test</div>
</body>
</html>
10 changes: 10 additions & 0 deletions test/fixtures/html/basic-include-with-unicode-BOM.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<!--=include test-with-unicode-BOM.html -->
</body>
</html>
1 change: 1 addition & 0 deletions test/fixtures/html/test-with-unicode-BOM.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>This is a test</div>
21 changes: 20 additions & 1 deletion test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,23 @@ describe("gulp-include", function () {
}))
.pipe(assert.end(done));
});
})

it('should strip unicode byte order marks from included files', function (done) {
var file = new gutil.File({
base: "test/fixtures/",
path: "test/fixtures/html/basic-include-with-unicode-BOM.html",
contents: fs.readFileSync("test/fixtures/html/basic-include-with-unicode-BOM.html")
});

testInclude = include();
testInclude.on("data", function (newFile) {
should.exist(newFile);
should.exist(newFile.contents);

String(newFile.contents).should.equal(String(fs.readFileSync("test/expected/html/basic-include-output-with-unicode-BOM.html"), "utf8"))
done();
});

testInclude.write(file);
})
})