Skip to content

Commit 9d2d2cb

Browse files
committed
Stripping BOM by default
1 parent 1ef3a7a commit 9d2d2cb

File tree

7 files changed

+73
-2
lines changed

7 files changed

+73
-2
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "genetis",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "",
55
"main": "src/index.js",
66
"bin": "src/cli.js",

src/options/defaultOptions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"partialExtensions": [".html", ".htm"],
88
"clean": true,
99
"fileEncoding": "utf8",
10+
"stripBom": true,
1011
"specialSlots": {
1112
"head": "head"
1213
}

src/process/getTemplates.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ const log = require('../log/log');
44

55
module.exports = async function getTemplates(file, options) {
66
let html = await fs.promises.readFile(file, options.fileEncoding);
7+
8+
if(options.stripBom) {
9+
html = html.replace(/^\uFEFF/, '');
10+
}
11+
712
let templates;
813
if(isRootHtml(html)) {
914
templates = [];

test/stripBom/src/_template.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title itemprop="title"></title>
8+
</head>
9+
<body>
10+
<h1>BOM Test</h1>
11+
<slot></slot>
12+
</body>
13+
</html>

test/stripBom/src/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>Content with a BOM</p>

test/stripBom/stripBom.spec.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const build = require('../../src/index');
2+
const fs = require('fs');
3+
const JSDOM = require('jsdom').JSDOM;
4+
const encoding = 'utf8';
5+
6+
describe('stripBom default', () => {
7+
const outputFile = './test/stripBom/dist/default/index.html';
8+
9+
beforeAll(async () => {
10+
await build({
11+
input: './test/stripBom/src',
12+
output: './test/stripBom/dist/default'
13+
});
14+
});
15+
16+
describe('index.html', () => {
17+
let html;
18+
19+
beforeAll(async () => {
20+
html = await fs.promises.readFile(outputFile, encoding);
21+
});
22+
23+
it('has no BOM', () => {
24+
expect(/\uFEFF/.test(html)).toEqual(false);
25+
});
26+
});
27+
});
28+
29+
describe('stripBom false', () => {
30+
const outputFile = './test/stripBom/dist/false/index.html';
31+
32+
beforeAll(async () => {
33+
await build({
34+
input: './test/stripBom/src',
35+
output: './test/stripBom/dist/false',
36+
stripBom: false
37+
});
38+
});
39+
40+
describe('index.html', () => {
41+
let html;
42+
43+
beforeAll(async () => {
44+
html = await fs.promises.readFile(outputFile, encoding);
45+
});
46+
47+
it('has a BOM in the content', () => {
48+
expect(/\uFEFF<p>/.test(html)).toEqual(true);
49+
});
50+
});
51+
});

0 commit comments

Comments
 (0)