Skip to content

Commit

Permalink
fix: Parse error with : when using fromUrl()
Browse files Browse the repository at this point in the history
Fixes #140
  • Loading branch information
jhnns committed Jun 30, 2022
1 parent f226197 commit 09071e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/from-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ describe(fromUrl.name, () => {
expect(fromUrl("1:2:3:4:5:6:7:8")).toBe("[1:2:3:4:5:6:7:8]");
});

// https://github.com/peerigon/parse-domain/issues/140
test("it doesn't get confused with other : characters", () => {
expect(
fromUrl(
"http://www.example.com/search?updated-max=2020-04-16T09:14:00+10:00"
)
).toBe("www.example.com");
});

test("it returns the NO_HOSTNAME symbol for invalid URLs", () => {
expect(fromUrl(":8080/path?query")).toBe(NO_HOSTNAME);
expect(fromUrl("/path?query")).toBe(NO_HOSTNAME);
Expand Down
3 changes: 2 additions & 1 deletion src/from-url.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const urlPattern = /^[a-z][*+.a-z-]+:\/\//i;
const invalidIpv6Pattern = /^([a-z][*+.a-z-]+:\/\/)([^[].*:[^/?]*:[^/?]*)(.*)/i;
const invalidIpv6Pattern =
/^([a-z][*+.a-z-]+:\/\/)([^[][^/?]*:[^/?]*:[^/?]*)(.*)/i;

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

Expand Down

0 comments on commit 09071e6

Please sign in to comment.