Skip to content

Commit a3f9fde

Browse files
authored
Merge pull request #3 from sanfrancesco/fix-html-file-detection
Fix HTML file detection when dots are in path
2 parents a9e7375 + 3467a70 commit a3f9fde

File tree

4 files changed

+42
-24
lines changed

4 files changed

+42
-24
lines changed

lib/util.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,14 @@ const parseUriField = uri => {
1616
return JSON.parse(fromBase64(uri.slice(1)));
1717
};
1818

19-
const isHtml = urlStr => {
20-
const parsedUrl = url.parse(urlStr);
21-
const path = parsedUrl.pathname;
22-
const basename = path.split("/").pop();
23-
24-
if (basename === "") return true;
25-
26-
// doesn't detect index.whatever.html (multiple dots)
27-
const hasHtmlOrNoExtension = !!basename.match(/^(([^.]|\.html?)+)$/);
28-
29-
if (hasHtmlOrNoExtension) return true;
30-
31-
// hack to handle basenames with multiple dots: index.whatever.html
32-
const endsInHtml = !!basename.match(/.html?$/);
33-
34-
if (endsInHtml) return true;
35-
36-
return false;
19+
const isHtml = require("prerendercloud").util.urlPathIsHtml;
20+
21+
module.exports = {
22+
USER_AGENT_PLACEHOLDER,
23+
toBase64,
24+
fromBase64,
25+
createUri,
26+
getHeader,
27+
parseUriField,
28+
isHtml
3729
};
38-
39-
module.exports = { USER_AGENT_PLACEHOLDER, toBase64, fromBase64, createUri, getHeader, parseUriField, isHtml };

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"serverless": "1.24.1"
77
},
88
"dependencies": {
9-
"prerendercloud": "^1.23.2"
9+
"prerendercloud": "1.27.0"
1010
}
1111
}

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+
});

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,9 +1300,9 @@ prepend-http@^2.0.0:
13001300
version "2.0.0"
13011301
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
13021302

1303-
prerendercloud@^1.23.2:
1304-
version "1.23.2"
1305-
resolved "https://registry.yarnpkg.com/prerendercloud/-/prerendercloud-1.23.2.tgz#297981b968b0944143b6915a91fce258964a3933"
1303+
prerendercloud@1.27.0:
1304+
version "1.27.0"
1305+
resolved "https://registry.yarnpkg.com/prerendercloud/-/prerendercloud-1.27.0.tgz#992c64a1420aeb20c02b2c19dd740d64a5ad8cff"
13061306
dependencies:
13071307
debug "^2.2.0"
13081308
got-lite "^8.0.1"

0 commit comments

Comments
 (0)