Skip to content

Commit 2aecd72

Browse files
committed
Fix HTML file detection when dots are in path
1 parent a9e7375 commit 2aecd72

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/util.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,20 @@ const isHtml = urlStr => {
3333

3434
if (endsInHtml) return true;
3535

36+
// hack to detect extensions that are not HTML so we can handle
37+
// paths with dots in them
38+
const endsInOtherExtension = basename.match(/\.[a-zA-Z]{1,5}$/);
39+
if (!endsInOtherExtension) return true;
40+
3641
return false;
3742
};
3843

39-
module.exports = { USER_AGENT_PLACEHOLDER, toBase64, fromBase64, createUri, getHeader, parseUriField, isHtml };
44+
module.exports = {
45+
USER_AGENT_PLACEHOLDER,
46+
toBase64,
47+
fromBase64,
48+
createUri,
49+
getHeader,
50+
parseUriField,
51+
isHtml
52+
};

spec/utilSpec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const util = require("../lib/util");
2+
3+
describe("util", function() {
4+
describe("isHtml", function() {
5+
it("detects no extension", function() {
6+
expect(util.isHtml("/")).toBe(true);
7+
});
8+
it("detects html", function() {
9+
expect(util.isHtml("index.html")).toBe(true);
10+
});
11+
it("detects htm", function() {
12+
expect(util.isHtml("index.htm")).toBe(true);
13+
});
14+
it("detects double dot html", function() {
15+
expect(util.isHtml("index.bak.html")).toBe(true);
16+
});
17+
it("does not detect js", function() {
18+
expect(util.isHtml("index.js")).toBe(false);
19+
});
20+
it("handles miscellaneous dots", function() {
21+
expect(
22+
util.isHtml(
23+
"categories/1234;lat=-999999.8888888;lng=12341234.13371337;location=SanFrancisco"
24+
)
25+
).toBe(true);
26+
});
27+
});
28+
});

0 commit comments

Comments
 (0)