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SAAS;aACtC,OAAO,CAAE,OAAO,EAAE,OAAO,CAAE,CAAE,SAAS;aACtC,OAAO,CAAE,OAAO,EAAE,OAAO,CAAC,CAAG,SAAS;aACtC,OAAO,CAAE,OAAO,EAAE,MAAM,CAAE,CAAG,SAAS;aACtC,OAAO,CAAE,OAAO,EAAE,MAAM,CAAE,CAAC,CAAE,SAAS;QAExC,IAAI;YACH,oDAAoD;YACpD,OAAO,kBAAkB,CAAE,4BAA4B,CAAE,CAAC;SAC1D;QAAC,OAAO,CAAC,EAAG,EAAG,+CAA+C;YAC9D,OAAO,4BAA4B,CAAC;SACpC;IACF,CAAC;IAEF,eAAC;AAAD,CA7RA,AA6RC,CA7R6B,KAAK,GA6RlC","file":"url-match.js","sourcesContent":["import { Match, MatchConfig } from \"./match\";\nimport { StripPrefixConfigObj, UrlMatchTypeOptions } from \"../autolinker\";\n\n/**\n * @class Autolinker.match.Url\n * @extends Autolinker.match.Match\n *\n * Represents a Url match found in an input string which should be Autolinked.\n *\n * See this class's superclass ({@link Autolinker.match.Match}) for more details.\n */\nexport class UrlMatch extends Match {\n\n\t/**\n\t * @cfg {String} url (required)\n\t *\n\t * The url that was matched.\n\t */\n\tprivate url: string = ''; // default value just to get the above doc comment in the ES5 output and documentation generator\n\n\t/**\n\t * @cfg {\"scheme\"/\"www\"/\"tld\"} urlMatchType (required)\n\t *\n\t * The type of URL match that this class represents. This helps to determine\n\t * if the match was made in the original text with a prefixed scheme (ex:\n\t * 'http://www.google.com'), a prefixed 'www' (ex: 'www.google.com'), or\n\t * was matched by a known top-level domain (ex: 'google.com').\n\t */\n\tprivate readonly urlMatchType: UrlMatchTypeOptions = 'scheme'; // default value just to get the above doc comment in the ES5 output and documentation generator\n\n\t/**\n\t * @cfg {Boolean} protocolUrlMatch (required)\n\t *\n\t * `true` if the URL is a match which already has a protocol (i.e.\n\t * 'http://'), `false` if the match was from a 'www' or known TLD match.\n\t */\n\tprivate readonly protocolUrlMatch: boolean = false; // default value just to get the above doc comment in the ES5 output and documentation generator\n\n\t/**\n\t * @cfg {Boolean} protocolRelativeMatch (required)\n\t *\n\t * `true` if the URL is a protocol-relative match. A protocol-relative match\n\t * is a URL that starts with '//', and will be either http:// or https://\n\t * based on the protocol that the site is loaded under.\n\t */\n\tprivate readonly protocolRelativeMatch: boolean = false; // default value just to get the above doc comment in the ES5 output and documentation generator\n\n\t/**\n\t * @cfg {Object} stripPrefix (required)\n\t *\n\t * The Object form of {@link Autolinker#cfg-stripPrefix}.\n\t */\n\tprivate readonly stripPrefix: Required<StripPrefixConfigObj> = { scheme: true, www: true }; // default value just to get the above doc comment in the ES5 output and documentation generator\n\n\t/**\n\t * @cfg {Boolean} stripTrailingSlash (required)\n\t * @inheritdoc Autolinker#cfg-stripTrailingSlash\n\t */\n\tprivate readonly stripTrailingSlash: boolean = true; // default value just to get the above doc comment in the ES5 output and documentation generator\n\n\t/**\n\t * @cfg {Boolean} decodePercentEncoding (required)\n\t * @inheritdoc Autolinker#cfg-decodePercentEncoding\n\t */\n\tprivate readonly decodePercentEncoding: boolean = true; // default value just to get the above doc comment in the ES5 output and documentation generator\n\n\t/**\n\t * @private\n\t * @property {RegExp} schemePrefixRegex\n\t *\n\t * A regular expression used to remove the 'http://' or 'https://' from\n\t * URLs.\n\t */\n\tschemePrefixRegex = /^(https?:\\/\\/)?/i;\n\n\t/**\n\t * @private\n\t * @property {RegExp} wwwPrefixRegex\n\t *\n\t * A regular expression used to remove the 'www.' from URLs.\n\t */\n\twwwPrefixRegex = /^(https?:\\/\\/)?(www\\.)?/i;\n\n\t/**\n\t * @private\n\t * @property {RegExp} protocolRelativeRegex\n\t *\n\t * The regular expression used to remove the protocol-relative '//' from the {@link #url} string, for purposes\n\t * of {@link #getAnchorText}. A protocol-relative URL is, for example, \"//yahoo.com\"\n\t */\n\tprotocolRelativeRegex = /^\\/\\//;\n\n\t/**\n\t * @private\n\t * @property {Boolean} protocolPrepended\n\t *\n\t * Will be set to `true` if the 'http://' protocol has been prepended to the {@link #url} (because the\n\t * {@link #url} did not have a protocol)\n\t */\n\tprotocolPrepended = false;\n\n\n\t/**\n\t * @method constructor\n\t * @param {Object} cfg The configuration properties for the Match\n\t * instance, specified in an Object (map).\n\t */\n\tconstructor( cfg: UrlMatchConfig ) {\n\t\tsuper( cfg );\n\n\t\tthis.urlMatchType = cfg.urlMatchType;\n\t\tthis.url = cfg.url;\n\t\tthis.protocolUrlMatch = cfg.protocolUrlMatch;\n\t\tthis.protocolRelativeMatch = cfg.protocolRelativeMatch;\n\t\tthis.stripPrefix = cfg.stripPrefix;\n\t\tthis.stripTrailingSlash = cfg.stripTrailingSlash;\n\t\tthis.decodePercentEncoding = cfg.decodePercentEncoding;\n\t}\n\n\n\t/**\n\t * Returns a string name for the type of match that this class represents.\n\t * For the case of UrlMatch, returns 'url'.\n\t *\n\t * @return {String}\n\t */\n\tgetType() {\n\t\treturn 'url';\n\t}\n\n\n\t/**\n\t * Returns a string name for the type of URL match that this class\n\t * represents.\n\t *\n\t * This helps to determine if the match was made in the original text with a\n\t * prefixed scheme (ex: 'http://www.google.com'), a prefixed 'www' (ex:\n\t * 'www.google.com'), or was matched by a known top-level domain (ex:\n\t * 'google.com').\n\t *\n\t * @return {\"scheme\"/\"www\"/\"tld\"}\n\t */\n\tgetUrlMatchType() {\n\t\treturn this.urlMatchType;\n\t}\n\n\n\t/**\n\t * Returns the url that was matched, assuming the protocol to be 'http://' if the original\n\t * match was missing a protocol.\n\t *\n\t * @return {String}\n\t */\n\tgetUrl() {\n\t\tlet url = this.url;\n\n\t\t// if the url string doesn't begin with a protocol, assume 'http://'\n\t\tif( !this.protocolRelativeMatch && !this.protocolUrlMatch && !this.protocolPrepended ) {\n\t\t\turl = this.url = 'http://' + url;\n\n\t\t\tthis.protocolPrepended = true;\n\t\t}\n\n\t\treturn url;\n\t}\n\n\n\t/**\n\t * Returns the anchor href that should be generated for the match.\n\t *\n\t * @return {String}\n\t */\n\tgetAnchorHref() {\n\t\tlet url = this.getUrl();\n\n\t\treturn url.replace( /&amp;/g, '&' ); // any &amp;'s in the URL should be converted back to '&' if they were displayed as &amp; in the source html\n\t}\n\n\n\t/**\n\t * Returns the anchor text that should be generated for the match.\n\t *\n\t * @return {String}\n\t */\n\tgetAnchorText() {\n\t\tlet anchorText = this.getMatchedText();\n\n\t\tif( this.protocolRelativeMatch ) {\n\t\t\t// Strip off any protocol-relative '//' from the anchor text\n\t\t\tanchorText = this.stripProtocolRelativePrefix( anchorText );\n\t\t}\n\t\tif( this.stripPrefix.scheme ) {\n\t\t\tanchorText = this.stripSchemePrefix( anchorText );\n\t\t}\n\t\tif( this.stripPrefix.www ) {\n\t\t\tanchorText = this.stripWwwPrefix( anchorText );\n\t\t}\n\t\tif( this.stripTrailingSlash ) {\n\t\t\tanchorText = this.removeTrailingSlash( anchorText ); // remove trailing slash, if there is one\n\t\t}\n\t\tif( this.decodePercentEncoding ) {\n\t\t\tanchorText = this.removePercentEncoding( anchorText );\n\t\t}\n\n\t\treturn anchorText;\n\t}\n\n\n\t// ---------------------------------------\n\n\t// Utility Functionality\n\n\t/**\n\t * Strips the scheme prefix (such as \"http://\" or \"https://\") from the given\n\t * `url`.\n\t *\n\t * @private\n\t * @param {String} url The text of the anchor that is being generated, for\n\t * which to strip off the url scheme.\n\t * @return {String} The `url`, with the scheme stripped.\n\t */\n\tprivate stripSchemePrefix( url: string ) {\n\t\treturn url.replace( this.schemePrefixRegex, '' );\n\t}\n\n\n\t/**\n\t * Strips the 'www' prefix from the given `url`.\n\t *\n\t * @private\n\t * @param {String} url The text of the anchor that is being generated, for\n\t * which to strip off the 'www' if it exists.\n\t * @return {String} The `url`, with the 'www' stripped.\n\t */\n\tprivate stripWwwPrefix( url: string ) {\n\t\treturn url.replace( this.wwwPrefixRegex, '$1' ); // leave any scheme ($1), it one exists\n\t}\n\n\n\t/**\n\t * Strips any protocol-relative '//' from the anchor text.\n\t *\n\t * @private\n\t * @param {String} text The text of the anchor that is being generated, for which to strip off the\n\t * protocol-relative prefix (such as stripping off \"//\")\n\t * @return {String} The `anchorText`, with the protocol-relative prefix stripped.\n\t */\n\tprivate stripProtocolRelativePrefix( text: string ) {\n\t\treturn text.replace( this.protocolRelativeRegex, '' );\n\t}\n\n\n\t/**\n\t * Removes any trailing slash from the given `anchorText`, in preparation for the text to be displayed.\n\t *\n\t * @private\n\t * @param {String} anchorText The text of the anchor that is being generated, for which to remove any trailing\n\t * slash ('/') that may exist.\n\t * @return {String} The `anchorText`, with the trailing slash removed.\n\t */\n\tprivate removeTrailingSlash( anchorText: string ) {\n\t\tif( anchorText.charAt( anchorText.length - 1 ) === '/' ) {\n\t\t\tanchorText = anchorText.slice( 0, -1 );\n\t\t}\n\t\treturn anchorText;\n\t}\n\n\t/**\n\t * Decodes percent-encoded characters from the given `anchorText`, in \n\t * preparation for the text to be displayed.\n\t *\n\t * @private\n\t * @param {String} anchorText The text of the anchor that is being \n\t * generated, for which to decode any percent-encoded characters.\n\t * @return {String} The `anchorText`, with the percent-encoded characters \n\t * decoded.\n\t */\n\tprivate removePercentEncoding( anchorText: string ) {\n\t\t// First, convert a few of the known % encodings to the corresponding\n\t\t// HTML entities that could accidentally be interpretted as special\n\t\t// HTML characters\n\t\tconst preProcessedEntityAnchorText = anchorText\n\t\t\t.replace( /%22/gi, '&quot;' ) // \" char\n\t\t\t.replace( /%26/gi, '&amp;' ) // & char\n\t\t\t.replace( /%27/gi, '&#39;') // ' char\n\t\t\t.replace( /%3C/gi, '&lt;' ) // < char\n\t\t\t.replace( /%3E/gi, '&gt;' ); // > char\n\n\t\ttry {\n\t\t\t// Now attempt to decode the rest of the anchor text\n\t\t\treturn decodeURIComponent( preProcessedEntityAnchorText );\n\t\t} catch( e ) { // Invalid % escape sequence in the anchor text\n\t\t\treturn preProcessedEntityAnchorText;\n\t\t}\n\t}\n\n}\n\n\nexport interface UrlMatchConfig extends MatchConfig {\n\turl: string;\n\turlMatchType: UrlMatchTypeOptions;\n\tprotocolUrlMatch: boolean;\n\tprotocolRelativeMatch: boolean;\n\tstripPrefix: Required<StripPrefixConfigObj>;\n\tstripTrailingSlash: boolean;\n\tdecodePercentEncoding: boolean;\n}\n"]}