Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return null if urlSplit is null - fix issues 32 and 61 #70

Merged
merged 1 commit into from May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/parseDomain.js
Expand Up @@ -62,8 +62,13 @@ function parseDomain(url, options) {

const normalizedOptions = normalize.options(options);

// urlSplit can't be null because urlParts will always match at the third capture
urlSplit = normalizedUrl.match(urlParts);

// urlSplit is null if the url contains certain characters like '\n', '\r'.
if (urlSplit === null) {
return null;
}

domain = urlSplit[3]; // domain will now be something like sub.domain.example.com

tld = matchTld(domain, normalizedOptions);
Expand Down
9 changes: 9 additions & 0 deletions test/parseDomain.test.js
Expand Up @@ -144,6 +144,15 @@ describe("parseDomain(url)", () => {
expect(parseDomain("")).to.equal(null);
});

it("should return null if the given value contains invalid characters", () => {
expect(parseDomain("http://hell.d\ne.ibm.com")).to.equal(null);
expect(parseDomain("\xa0")).to.equal(null);
});

it("should return null if the given is an empty string with a space character", () => {
expect(parseDomain(" ")).to.equal(null);
});

it("should work with domains that could match multiple tlds", () => {
expect(parseDomain("http://hello.de.ibm.com")).to.eql({
subdomain: "hello.de",
Expand Down