[d24f17c] | 1 | /**
|
---|
| 2 | * @private
|
---|
| 3 | * @class Autolinker.matcher.UrlMatchValidator
|
---|
| 4 | * @singleton
|
---|
| 5 | *
|
---|
| 6 | * Used by Autolinker to filter out false URL positives from the
|
---|
| 7 | * {@link Autolinker.matcher.Url UrlMatcher}.
|
---|
| 8 | *
|
---|
| 9 | * Due to the limitations of regular expressions (including the missing feature
|
---|
| 10 | * of look-behinds in JS regular expressions), we cannot always determine the
|
---|
| 11 | * validity of a given match. This class applies a bit of additional logic to
|
---|
| 12 | * filter out any false positives that have been matched by the
|
---|
| 13 | * {@link Autolinker.matcher.Url UrlMatcher}.
|
---|
| 14 | */
|
---|
| 15 | export declare class UrlMatchValidator {
|
---|
| 16 | /**
|
---|
| 17 | * Regex to test for a full protocol, with the two trailing slashes. Ex: 'http://'
|
---|
| 18 | *
|
---|
| 19 | * @private
|
---|
| 20 | * @property {RegExp} hasFullProtocolRegex
|
---|
| 21 | */
|
---|
| 22 | static hasFullProtocolRegex: RegExp;
|
---|
| 23 | /**
|
---|
| 24 | * Regex to find the URI scheme, such as 'mailto:'.
|
---|
| 25 | *
|
---|
| 26 | * This is used to filter out 'javascript:' and 'vbscript:' schemes.
|
---|
| 27 | *
|
---|
| 28 | * @private
|
---|
| 29 | * @property {RegExp} uriSchemeRegex
|
---|
| 30 | */
|
---|
| 31 | static uriSchemeRegex: RegExp;
|
---|
| 32 | /**
|
---|
| 33 | * Regex to determine if at least one word char exists after the protocol (i.e. after the ':')
|
---|
| 34 | *
|
---|
| 35 | * @private
|
---|
| 36 | * @property {RegExp} hasWordCharAfterProtocolRegex
|
---|
| 37 | */
|
---|
| 38 | static hasWordCharAfterProtocolRegex: RegExp;
|
---|
| 39 | /**
|
---|
| 40 | * Regex to determine if the string is a valid IP address
|
---|
| 41 | *
|
---|
| 42 | * @private
|
---|
| 43 | * @property {RegExp} ipRegex
|
---|
| 44 | */
|
---|
| 45 | static ipRegex: RegExp;
|
---|
| 46 | /**
|
---|
| 47 | * Determines if a given URL match found by the {@link Autolinker.matcher.Url UrlMatcher}
|
---|
| 48 | * is valid. Will return `false` for:
|
---|
| 49 | *
|
---|
| 50 | * 1) URL matches which do not have at least have one period ('.') in the
|
---|
| 51 | * domain name (effectively skipping over matches like "abc:def").
|
---|
| 52 | * However, URL matches with a protocol will be allowed (ex: 'http://localhost')
|
---|
| 53 | * 2) URL matches which do not have at least one word character in the
|
---|
| 54 | * domain name (effectively skipping over matches like "git:1.0").
|
---|
| 55 | * However, URL matches with a protocol will be allowed (ex: 'intra-net://271219.76')
|
---|
| 56 | * 3) A protocol-relative url match (a URL beginning with '//') whose
|
---|
| 57 | * previous character is a word character (effectively skipping over
|
---|
| 58 | * strings like "abc//google.com")
|
---|
| 59 | *
|
---|
| 60 | * Otherwise, returns `true`.
|
---|
| 61 | *
|
---|
| 62 | * @param {String} urlMatch The matched URL, if there was one. Will be an
|
---|
| 63 | * empty string if the match is not a URL match.
|
---|
| 64 | * @param {String} protocolUrlMatch The match URL string for a protocol
|
---|
| 65 | * match. Ex: 'http://yahoo.com'. This is used to match something like
|
---|
| 66 | * 'http://localhost', where we won't double check that the domain name
|
---|
| 67 | * has at least one '.' in it.
|
---|
| 68 | * @return {Boolean} `true` if the match given is valid and should be
|
---|
| 69 | * processed, or `false` if the match is invalid and/or should just not be
|
---|
| 70 | * processed.
|
---|
| 71 | */
|
---|
| 72 | static isValid(urlMatch: string, protocolUrlMatch: string): boolean;
|
---|
| 73 | static isValidIpAddress(uriSchemeMatch: string): boolean;
|
---|
| 74 | private static containsMultipleDots;
|
---|
| 75 | /**
|
---|
| 76 | * Determines if the URI scheme is a valid scheme to be autolinked. Returns
|
---|
| 77 | * `false` if the scheme is 'javascript:' or 'vbscript:'
|
---|
| 78 | *
|
---|
| 79 | * @private
|
---|
| 80 | * @param {String} uriSchemeMatch The match URL string for a full URI scheme
|
---|
| 81 | * match. Ex: 'http://yahoo.com' or 'mailto:a@a.com'.
|
---|
| 82 | * @return {Boolean} `true` if the scheme is a valid one, `false` otherwise.
|
---|
| 83 | */
|
---|
| 84 | static isValidUriScheme(uriSchemeMatch: string): boolean;
|
---|
| 85 | /**
|
---|
| 86 | * Determines if a URL match does not have either:
|
---|
| 87 | *
|
---|
| 88 | * a) a full protocol (i.e. 'http://'), or
|
---|
| 89 | * b) at least one dot ('.') in the domain name (for a non-full-protocol
|
---|
| 90 | * match).
|
---|
| 91 | *
|
---|
| 92 | * Either situation is considered an invalid URL (ex: 'git:d' does not have
|
---|
| 93 | * either the '://' part, or at least one dot in the domain name. If the
|
---|
| 94 | * match was 'git:abc.com', we would consider this valid.)
|
---|
| 95 | *
|
---|
| 96 | * @private
|
---|
| 97 | * @param {String} urlMatch The matched URL, if there was one. Will be an
|
---|
| 98 | * empty string if the match is not a URL match.
|
---|
| 99 | * @param {String} protocolUrlMatch The match URL string for a protocol
|
---|
| 100 | * match. Ex: 'http://yahoo.com'. This is used to match something like
|
---|
| 101 | * 'http://localhost', where we won't double check that the domain name
|
---|
| 102 | * has at least one '.' in it.
|
---|
| 103 | * @return {Boolean} `true` if the URL match does not have a full protocol,
|
---|
| 104 | * or at least one dot ('.') in a non-full-protocol match.
|
---|
| 105 | */
|
---|
| 106 | static urlMatchDoesNotHaveProtocolOrDot(urlMatch: string, protocolUrlMatch: string): boolean;
|
---|
| 107 | /**
|
---|
| 108 | * Determines if a URL match does not have either:
|
---|
| 109 | *
|
---|
| 110 | * a) a full protocol (i.e. 'http://'), or
|
---|
| 111 | * b) at least one word character after the protocol (i.e. in the domain name)
|
---|
| 112 | *
|
---|
| 113 | * At least one letter character must exist in the domain name after a
|
---|
| 114 | * protocol match. Ex: skip over something like "git:1.0"
|
---|
| 115 | *
|
---|
| 116 | * @private
|
---|
| 117 | * @param {String} urlMatch The matched URL, if there was one. Will be an
|
---|
| 118 | * empty string if the match is not a URL match.
|
---|
| 119 | * @param {String} protocolUrlMatch The match URL string for a protocol
|
---|
| 120 | * match. Ex: 'http://yahoo.com'. This is used to know whether or not we
|
---|
| 121 | * have a protocol in the URL string, in order to check for a word
|
---|
| 122 | * character after the protocol separator (':').
|
---|
| 123 | * @return {Boolean} `true` if the URL match does not have a full protocol, or
|
---|
| 124 | * at least one word character in it, `false` otherwise.
|
---|
| 125 | */
|
---|
| 126 | static urlMatchDoesNotHaveAtLeastOneWordChar(urlMatch: string, protocolUrlMatch: string): boolean;
|
---|
| 127 | }
|
---|