Skip to content

Commit ad6ea62

Browse files
authored
Merge pull request #184 from gregjacobs/dont-allow-multiple-dots
Don't allow multiple dots
2 parents 7f8e87d + 416de9f commit ad6ea62

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/matcher/UrlMatchValidator.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ Autolinker.matcher.UrlMatchValidator = {
8080
( protocolUrlMatch && !this.isValidUriScheme( protocolUrlMatch ) ) ||
8181
this.urlMatchDoesNotHaveProtocolOrDot( urlMatch, protocolUrlMatch ) || // At least one period ('.') must exist in the URL match for us to consider it an actual URL, *unless* it was a full protocol match (like 'http://localhost')
8282
(this.urlMatchDoesNotHaveAtLeastOneWordChar( urlMatch, protocolUrlMatch ) && // At least one letter character must exist in the domain name after a protocol match. Ex: skip over something like "git:1.0"
83-
!this.isValidIpAddress( urlMatch ) // Except if it's an IP address
84-
)
83+
!this.isValidIpAddress( urlMatch )) || // Except if it's an IP address
84+
this.containsMultipleDots( urlMatch )
8585
) {
8686
return false;
8787
}
@@ -97,6 +97,10 @@ Autolinker.matcher.UrlMatchValidator = {
9797
return uriScheme !== null;
9898
},
9999

100+
containsMultipleDots : function ( urlMatch ) {
101+
return urlMatch.indexOf("..") > -1;
102+
},
103+
100104
/**
101105
* Determines if the URI scheme is a valid scheme to be autolinked. Returns
102106
* `false` if the scheme is 'javascript:' or 'vbscript:'
@@ -164,4 +168,4 @@ Autolinker.matcher.UrlMatchValidator = {
164168
}
165169
}
166170

167-
};
171+
};

tests/matcher/UrlSpec.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ describe( "Autolinker.matcher.Url", function() {
9393
MatchChecker.expectUrlMatch( matches[ 0 ], 'https://gitlab.example.com/search?utf8=✓&search=mysearch&group_id=&project_id=42&search_code=true&repository_ref=master', 0 );
9494
});
9595

96+
it( 'should not match an address with multiple dots', function() {
97+
var matches = matcher.parseMatches( 'hello:...world' );
98+
var othermatches = matcher.parseMatches( 'hello:wo.....rld' );
99+
100+
expect( matches.length ).toBe( 0 );
101+
expect( othermatches.length ).toBe( 0 );
102+
});
103+
96104

97105
describe( 'protocol-relative URLs', function() {
98106

@@ -130,4 +138,4 @@ describe( "Autolinker.matcher.Url", function() {
130138

131139
} );
132140

133-
} );
141+
} );

0 commit comments

Comments
 (0)