diff --git a/src/from-url.test.ts b/src/from-url.test.ts index 630cce7..4f08af8 100644 --- a/src/from-url.test.ts +++ b/src/from-url.test.ts @@ -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); diff --git a/src/from-url.ts b/src/from-url.ts index b50d64e..d87d05e 100644 --- a/src/from-url.ts +++ b/src/from-url.ts @@ -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");