Skip to content

Commit 09071e6

Browse files
committed
fix: Parse error with : when using fromUrl()
Fixes #140
1 parent f226197 commit 09071e6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/from-url.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ describe(fromUrl.name, () => {
6666
expect(fromUrl("1:2:3:4:5:6:7:8")).toBe("[1:2:3:4:5:6:7:8]");
6767
});
6868

69+
// https://github.com/peerigon/parse-domain/issues/140
70+
test("it doesn't get confused with other : characters", () => {
71+
expect(
72+
fromUrl(
73+
"http://www.example.com/search?updated-max=2020-04-16T09:14:00+10:00"
74+
)
75+
).toBe("www.example.com");
76+
});
77+
6978
test("it returns the NO_HOSTNAME symbol for invalid URLs", () => {
7079
expect(fromUrl(":8080/path?query")).toBe(NO_HOSTNAME);
7180
expect(fromUrl("/path?query")).toBe(NO_HOSTNAME);

src/from-url.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const urlPattern = /^[a-z][*+.a-z-]+:\/\//i;
2-
const invalidIpv6Pattern = /^([a-z][*+.a-z-]+:\/\/)([^[].*:[^/?]*:[^/?]*)(.*)/i;
2+
const invalidIpv6Pattern =
3+
/^([a-z][*+.a-z-]+:\/\/)([^[][^/?]*:[^/?]*:[^/?]*)(.*)/i;
34

45
export const NO_HOSTNAME: unique symbol = Symbol("NO_HOSTNAME");
56

0 commit comments

Comments
 (0)