Skip to content

Commit 1ff1a3e

Browse files
authored
Merge pull request #173 from olafleur/master
Add Autolink for IP addresses
2 parents f8b1ff3 + 0bb5066 commit 1ff1a3e

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

dist/Autolinker.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3450,6 +3450,13 @@ Autolinker.matcher.UrlMatchValidator = {
34503450
*/
34513451
hasWordCharAfterProtocolRegex : /:[^\s]*?[A-Za-z\u00C0-\u017F]/,
34523452

3453+
/**
3454+
* Regex to determine if the string is a valid IP address
3455+
*
3456+
* @private
3457+
* @property {RegExp} ipRegex
3458+
*/
3459+
ipRegex: /[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?/,
34533460

34543461
/**
34553462
* Determines if a given URL match found by the {@link Autolinker.matcher.Url UrlMatcher}
@@ -3480,7 +3487,9 @@ Autolinker.matcher.UrlMatchValidator = {
34803487
if(
34813488
( protocolUrlMatch && !this.isValidUriScheme( protocolUrlMatch ) ) ||
34823489
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')
3483-
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"
3490+
(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"
3491+
!this.isValidIpAddress( urlMatch ) // Except if it's an IP address
3492+
)
34843493
) {
34853494
return false;
34863495
}
@@ -3489,6 +3498,13 @@ Autolinker.matcher.UrlMatchValidator = {
34893498
},
34903499

34913500

3501+
isValidIpAddress : function ( uriSchemeMatch ) {
3502+
var newRegex = new RegExp(this.hasFullProtocolRegex.source + this.ipRegex.source);
3503+
var uriScheme = uriSchemeMatch.match( newRegex );
3504+
3505+
return uriScheme !== null;
3506+
},
3507+
34923508
/**
34933509
* Determines if the URI scheme is a valid scheme to be autolinked. Returns
34943510
* `false` if the scheme is 'javascript:' or 'vbscript:'

0 commit comments

Comments
 (0)