Skip to content

Commit

Permalink
Merge branch 'c960657-percent-encoding'
Browse files Browse the repository at this point in the history
  • Loading branch information
gregjacobs committed Nov 7, 2017
2 parents 616f145 + f068ab7 commit f99f494
Show file tree
Hide file tree
Showing 23 changed files with 288 additions and 34 deletions.
58 changes: 54 additions & 4 deletions dist/Autolinker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* Autolinker.js
* 1.5.0
* 1.6.0
*
* Copyright(c) 2017 Gregory Jacobs <greg@greg-jacobs.com>
* MIT License
Expand Down Expand Up @@ -139,6 +139,7 @@ var Autolinker = function( cfg ) {
this.newWindow = typeof cfg.newWindow === 'boolean' ? cfg.newWindow : true;
this.stripPrefix = this.normalizeStripPrefixCfg( cfg.stripPrefix );
this.stripTrailingSlash = typeof cfg.stripTrailingSlash === 'boolean' ? cfg.stripTrailingSlash : true;
this.decodePercentEncoding = typeof cfg.decodePercentEncoding === 'boolean' ? cfg.decodePercentEncoding : true;

// Validate the value of the `mention` cfg
var mention = this.mention;
Expand Down Expand Up @@ -240,7 +241,7 @@ Autolinker.parse = function( textOrHtml, options ) {
*
* Ex: 0.25.1
*/
Autolinker.version = '1.5.0';
Autolinker.version = '1.6.0';


Autolinker.prototype = {
Expand Down Expand Up @@ -371,6 +372,16 @@ Autolinker.prototype = {
* `http://google.com`.
*/

/**
* @cfg {Boolean} [decodePercentEncoding=true]
*
* `true` to decode percent-encoded characters in URL matches, `false` to keep
* the percent-encoded characters.
*
* Example when `true`: `https://en.wikipedia.org/wiki/San_Jos%C3%A9` will
* be displayed as `https://en.wikipedia.org/wiki/San_José`.
*/

/**
* @cfg {Number/Object} [truncate=0]
*
Expand Down Expand Up @@ -870,7 +881,7 @@ Autolinker.prototype = {
new matchersNs.Email( { tagBuilder: tagBuilder } ),
new matchersNs.Phone( { tagBuilder: tagBuilder } ),
new matchersNs.Mention( { tagBuilder: tagBuilder, serviceName: this.mention } ),
new matchersNs.Url( { tagBuilder: tagBuilder, stripPrefix: this.stripPrefix, stripTrailingSlash: this.stripTrailingSlash } )
new matchersNs.Url( { tagBuilder: tagBuilder, stripPrefix: this.stripPrefix, stripTrailingSlash: this.stripTrailingSlash, decodePercentEncoding: this.decodePercentEncoding } )
];

return ( this.matchers = matchers );
Expand Down Expand Up @@ -2935,6 +2946,10 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
* @inheritdoc Autolinker#cfg-stripTrailingSlash
*/

/**
* @cfg {Boolean} decodePercentEncoding (required)
* @inheritdoc Autolinker#cfg-decodePercentEncoding
*/

/**
* @constructor
Expand All @@ -2950,13 +2965,15 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
if( cfg.protocolRelativeMatch == null ) throw new Error( '`protocolRelativeMatch` cfg required' );
if( cfg.stripPrefix == null ) throw new Error( '`stripPrefix` cfg required' );
if( cfg.stripTrailingSlash == null ) throw new Error( '`stripTrailingSlash` cfg required' );
if( cfg.decodePercentEncoding == null ) throw new Error( '`decodePercentEncoding` cfg required' );

this.urlMatchType = cfg.urlMatchType;
this.url = cfg.url;
this.protocolUrlMatch = cfg.protocolUrlMatch;
this.protocolRelativeMatch = cfg.protocolRelativeMatch;
this.stripPrefix = cfg.stripPrefix;
this.stripTrailingSlash = cfg.stripTrailingSlash;
this.decodePercentEncoding = cfg.decodePercentEncoding;
},


Expand Down Expand Up @@ -3075,6 +3092,9 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
if( this.stripTrailingSlash ) {
anchorText = this.removeTrailingSlash( anchorText ); // remove trailing slash, if there is one
}
if( this.decodePercentEncoding ) {
anchorText = this.removePercentEncoding( anchorText);
}

return anchorText;
},
Expand Down Expand Up @@ -3137,6 +3157,28 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
anchorText = anchorText.slice( 0, -1 );
}
return anchorText;
},

/**
* Decodes percent-encoded characters from the given `anchorText`, in preparation for the text to be displayed.
*
* @private
* @param {String} anchorText The text of the anchor that is being generated, for which to decode any percent-encoded characters.
* @return {String} The `anchorText`, with the percent-encoded characters decoded.
*/
removePercentEncoding : function( anchorText ) {
try {
return decodeURIComponent( anchorText
.replace( /%22/gi, '&quot;' )
.replace( /%26/gi, '&amp;' )
.replace( /%27/gi, '&#39;')
.replace( /%3C/gi, '&lt;' )
.replace( /%3E/gi, '&gt;' )
);
} catch (e) {
// Invalid escape sequence.
return anchorText;
}
}

} );
Expand Down Expand Up @@ -3511,6 +3553,11 @@ Autolinker.matcher.Url = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
* @inheritdoc Autolinker#stripTrailingSlash
*/

/**
* @cfg {Boolean} decodePercentEncoding (required)
* @inheritdoc Autolinker#decodePercentEncoding
*/


/**
* @private
Expand Down Expand Up @@ -3644,6 +3691,7 @@ Autolinker.matcher.Url = Autolinker.Util.extend( Autolinker.matcher.Matcher, {

this.stripPrefix = cfg.stripPrefix;
this.stripTrailingSlash = cfg.stripTrailingSlash;
this.decodePercentEncoding = cfg.decodePercentEncoding;
},


Expand All @@ -3654,6 +3702,7 @@ Autolinker.matcher.Url = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
var matcherRegex = this.matcherRegex,
stripPrefix = this.stripPrefix,
stripTrailingSlash = this.stripTrailingSlash,
decodePercentEncoding = this.decodePercentEncoding,
tagBuilder = this.tagBuilder,
matches = [],
match;
Expand Down Expand Up @@ -3716,7 +3765,8 @@ Autolinker.matcher.Url = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
protocolUrlMatch : protocolUrlMatch,
protocolRelativeMatch : !!protocolRelativeMatch,
stripPrefix : stripPrefix,
stripTrailingSlash : stripTrailingSlash
stripTrailingSlash : stripTrailingSlash,
decodePercentEncoding : decodePercentEncoding,
} ) );
}

Expand Down
6 changes: 3 additions & 3 deletions dist/Autolinker.min.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/api/data-0cfafcc469bd1e77c3fc920bb1640cdf.js

This file was deleted.

1 change: 1 addition & 0 deletions docs/api/data-f36136e80946f52beafafdcdfb2138d1.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/api/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Autolinker v1.5.0 API Docs</title>
<title>Autolinker v1.6.0 API Docs</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="fragment" content="!">
Expand All @@ -13,7 +13,7 @@
<link rel="stylesheet" href="styles-3eba09980fa05ead185cb17d9c0deb0f.css" type="text/css" />

<script type="text/javascript" src="extjs/ext-all.js"></script>
<script type="text/javascript" src="data-0cfafcc469bd1e77c3fc920bb1640cdf.js"></script>
<script type="text/javascript" src="data-f36136e80946f52beafafdcdfb2138d1.js"></script>

<script type="text/javascript" src="app-0c945a27f43452df695771ddb60b3d14.js"></script>

Expand All @@ -22,9 +22,9 @@
</head>
<body id="ext-body">

<div id="loading"><span class="title">Autolinker v1.5.0 API Docs</span><span class="logo"></span></div>
<div id="loading"><span class="title">Autolinker v1.6.0 API Docs</span><span class="logo"></span></div>

<div id="header-content">Autolinker v1.5.0 API Docs</div>
<div id="header-content">Autolinker v1.6.0 API Docs</div>

<div id='categories-content' style='display:none'>
<div class='section'>
Expand Down Expand Up @@ -82,7 +82,7 @@ <h3>Others...</h3>



<div id='footer-content' style='display: none'>Generated on Mon 06 Nov 2017 21:26:57 by <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> 5.3.4.</div>
<div id='footer-content' style='display: none'>Generated on Mon 06 Nov 2017 21:39:34 by <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> 5.3.4.</div>



Expand Down
2 changes: 1 addition & 1 deletion docs/api/output/Autolinker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/api/output/Autolinker.match.Url.js

Large diffs are not rendered by default.

Loading

0 comments on commit f99f494

Please sign in to comment.