File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -62,8 +62,13 @@ function parseDomain(url, options) {
6262
6363 const normalizedOptions = normalize . options ( options ) ;
6464
65- // urlSplit can't be null because urlParts will always match at the third capture
6665 urlSplit = normalizedUrl . match ( urlParts ) ;
66+
67+ // urlSplit is null if the url contains certain characters like '\n', '\r'.
68+ if ( urlSplit === null ) {
69+ return null ;
70+ }
71+
6772 domain = urlSplit [ 3 ] ; // domain will now be something like sub.domain.example.com
6873
6974 tld = matchTld ( domain , normalizedOptions ) ;
Original file line number Diff line number Diff line change @@ -146,6 +146,15 @@ describe("parseDomain(url)", () => {
146146 expect ( parseDomain ( "\xa0" ) ) . to . equal ( null ) ;
147147 } ) ;
148148
149+ it ( "should return null if the given value contains invalid characters" , ( ) => {
150+ expect ( parseDomain ( "http://hell.d\ne.ibm.com" ) ) . to . equal ( null ) ;
151+ expect ( parseDomain ( "\xa0" ) ) . to . equal ( null ) ;
152+ } ) ;
153+
154+ it ( "should return null if the given is an empty string with a space character" , ( ) => {
155+ expect ( parseDomain ( " " ) ) . to . equal ( null ) ;
156+ } ) ;
157+
149158 it ( "should work with domains that could match multiple tlds" , ( ) => {
150159 expect ( parseDomain ( "http://hello.de.ibm.com" ) ) . to . eql ( {
151160 subdomain : "hello.de" ,
You can’t perform that action at this time.
0 commit comments