Skip to content

Commit 0c03ceb

Browse files
committed
Fix cases involving ><meta>
See jsdom/jsdom#2766.
1 parent 7bef90b commit 0c03ceb

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

lib/html-encoding-sniffer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ function getAttribute(buffer, i, l) {
132132
}
133133
// ">"
134134
if (c === 0x3E) {
135-
i++;
136135
break;
137136
}
138137
let name = "";

test/no-bom-charset-bracket.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head><meta charset="utf-8">
4+
</head>
5+
<body></body>
6+
</html>

test/tests.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,34 @@ describe("A file with no BOM and a <meta http-equiv> with no quotes", () => {
177177
});
178178
});
179179

180+
describe("A file with no BOM and a ><meta charset>", () => {
181+
const buffer = read("no-bom-charset-bracket.html");
182+
183+
it("should sniff as the charset value, given no options", () => {
184+
const sniffedEncoding = htmlEncodingSniffer(buffer);
185+
186+
assert.strictEqual(sniffedEncoding, "UTF-8");
187+
});
188+
189+
it("should sniff as the transport layer encoding, given that", () => {
190+
const sniffedEncoding = htmlEncodingSniffer(buffer, {
191+
transportLayerEncodingLabel: "windows-1251",
192+
defaultEncoding: "ISO-8859-16"
193+
});
194+
195+
assert.strictEqual(sniffedEncoding, "windows-1251");
196+
});
197+
198+
199+
it("should sniff as the charset value, given only a default encoding", () => {
200+
const sniffedEncoding = htmlEncodingSniffer(buffer, {
201+
defaultEncoding: "ISO-8859-16"
202+
});
203+
204+
assert.strictEqual(sniffedEncoding, "UTF-8");
205+
});
206+
});
207+
180208
for (const utf16Encoding of ["utf-16be", "utf-16", "utf-16le"]) {
181209
describe(`A file with a BOM and a <meta charset> of ${utf16Encoding}`, () => {
182210
const buffer = read(`no-bom-charset-${utf16Encoding}.html`);

0 commit comments

Comments
 (0)