Skip to content

Commit f99f494

Browse files
committed
Merge branch 'c960657-percent-encoding'
2 parents 616f145 + f068ab7 commit f99f494

23 files changed

+288
-34
lines changed

dist/Autolinker.js

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* Autolinker.js
3-
* 1.5.0
3+
* 1.6.0
44
*
55
* Copyright(c) 2017 Gregory Jacobs <greg@greg-jacobs.com>
66
* MIT License
@@ -139,6 +139,7 @@ var Autolinker = function( cfg ) {
139139
this.newWindow = typeof cfg.newWindow === 'boolean' ? cfg.newWindow : true;
140140
this.stripPrefix = this.normalizeStripPrefixCfg( cfg.stripPrefix );
141141
this.stripTrailingSlash = typeof cfg.stripTrailingSlash === 'boolean' ? cfg.stripTrailingSlash : true;
142+
this.decodePercentEncoding = typeof cfg.decodePercentEncoding === 'boolean' ? cfg.decodePercentEncoding : true;
142143

143144
// Validate the value of the `mention` cfg
144145
var mention = this.mention;
@@ -240,7 +241,7 @@ Autolinker.parse = function( textOrHtml, options ) {
240241
*
241242
* Ex: 0.25.1
242243
*/
243-
Autolinker.version = '1.5.0';
244+
Autolinker.version = '1.6.0';
244245

245246

246247
Autolinker.prototype = {
@@ -371,6 +372,16 @@ Autolinker.prototype = {
371372
* `http://google.com`.
372373
*/
373374

375+
/**
376+
* @cfg {Boolean} [decodePercentEncoding=true]
377+
*
378+
* `true` to decode percent-encoded characters in URL matches, `false` to keep
379+
* the percent-encoded characters.
380+
*
381+
* Example when `true`: `https://en.wikipedia.org/wiki/San_Jos%C3%A9` will
382+
* be displayed as `https://en.wikipedia.org/wiki/San_José`.
383+
*/
384+
374385
/**
375386
* @cfg {Number/Object} [truncate=0]
376387
*
@@ -870,7 +881,7 @@ Autolinker.prototype = {
870881
new matchersNs.Email( { tagBuilder: tagBuilder } ),
871882
new matchersNs.Phone( { tagBuilder: tagBuilder } ),
872883
new matchersNs.Mention( { tagBuilder: tagBuilder, serviceName: this.mention } ),
873-
new matchersNs.Url( { tagBuilder: tagBuilder, stripPrefix: this.stripPrefix, stripTrailingSlash: this.stripTrailingSlash } )
884+
new matchersNs.Url( { tagBuilder: tagBuilder, stripPrefix: this.stripPrefix, stripTrailingSlash: this.stripTrailingSlash, decodePercentEncoding: this.decodePercentEncoding } )
874885
];
875886

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

2949+
/**
2950+
* @cfg {Boolean} decodePercentEncoding (required)
2951+
* @inheritdoc Autolinker#cfg-decodePercentEncoding
2952+
*/
29382953

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

29542970
this.urlMatchType = cfg.urlMatchType;
29552971
this.url = cfg.url;
29562972
this.protocolUrlMatch = cfg.protocolUrlMatch;
29572973
this.protocolRelativeMatch = cfg.protocolRelativeMatch;
29582974
this.stripPrefix = cfg.stripPrefix;
29592975
this.stripTrailingSlash = cfg.stripTrailingSlash;
2976+
this.decodePercentEncoding = cfg.decodePercentEncoding;
29602977
},
29612978

29622979

@@ -3075,6 +3092,9 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
30753092
if( this.stripTrailingSlash ) {
30763093
anchorText = this.removeTrailingSlash( anchorText ); // remove trailing slash, if there is one
30773094
}
3095+
if( this.decodePercentEncoding ) {
3096+
anchorText = this.removePercentEncoding( anchorText);
3097+
}
30783098

30793099
return anchorText;
30803100
},
@@ -3137,6 +3157,28 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
31373157
anchorText = anchorText.slice( 0, -1 );
31383158
}
31393159
return anchorText;
3160+
},
3161+
3162+
/**
3163+
* Decodes percent-encoded characters from the given `anchorText`, in preparation for the text to be displayed.
3164+
*
3165+
* @private
3166+
* @param {String} anchorText The text of the anchor that is being generated, for which to decode any percent-encoded characters.
3167+
* @return {String} The `anchorText`, with the percent-encoded characters decoded.
3168+
*/
3169+
removePercentEncoding : function( anchorText ) {
3170+
try {
3171+
return decodeURIComponent( anchorText
3172+
.replace( /%22/gi, '&quot;' )
3173+
.replace( /%26/gi, '&amp;' )
3174+
.replace( /%27/gi, '&#39;')
3175+
.replace( /%3C/gi, '&lt;' )
3176+
.replace( /%3E/gi, '&gt;' )
3177+
);
3178+
} catch (e) {
3179+
// Invalid escape sequence.
3180+
return anchorText;
3181+
}
31403182
}
31413183

31423184
} );
@@ -3511,6 +3553,11 @@ Autolinker.matcher.Url = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
35113553
* @inheritdoc Autolinker#stripTrailingSlash
35123554
*/
35133555

3556+
/**
3557+
* @cfg {Boolean} decodePercentEncoding (required)
3558+
* @inheritdoc Autolinker#decodePercentEncoding
3559+
*/
3560+
35143561

35153562
/**
35163563
* @private
@@ -3644,6 +3691,7 @@ Autolinker.matcher.Url = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
36443691

36453692
this.stripPrefix = cfg.stripPrefix;
36463693
this.stripTrailingSlash = cfg.stripTrailingSlash;
3694+
this.decodePercentEncoding = cfg.decodePercentEncoding;
36473695
},
36483696

36493697

@@ -3654,6 +3702,7 @@ Autolinker.matcher.Url = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
36543702
var matcherRegex = this.matcherRegex,
36553703
stripPrefix = this.stripPrefix,
36563704
stripTrailingSlash = this.stripTrailingSlash,
3705+
decodePercentEncoding = this.decodePercentEncoding,
36573706
tagBuilder = this.tagBuilder,
36583707
matches = [],
36593708
match;
@@ -3716,7 +3765,8 @@ Autolinker.matcher.Url = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
37163765
protocolUrlMatch : protocolUrlMatch,
37173766
protocolRelativeMatch : !!protocolRelativeMatch,
37183767
stripPrefix : stripPrefix,
3719-
stripTrailingSlash : stripTrailingSlash
3768+
stripTrailingSlash : stripTrailingSlash,
3769+
decodePercentEncoding : decodePercentEncoding,
37203770
} ) );
37213771
}
37223772

dist/Autolinker.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/data-0cfafcc469bd1e77c3fc920bb1640cdf.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/api/data-f36136e80946f52beafafdcdfb2138d1.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>Autolinker v1.5.0 API Docs</title>
4+
<title>Autolinker v1.6.0 API Docs</title>
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
66
<meta http-equiv="X-UA-Compatible" content="chrome=1">
77
<meta name="fragment" content="!">
@@ -13,7 +13,7 @@
1313
<link rel="stylesheet" href="styles-3eba09980fa05ead185cb17d9c0deb0f.css" type="text/css" />
1414

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

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

@@ -22,9 +22,9 @@
2222
</head>
2323
<body id="ext-body">
2424

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

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

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

8383

8484

85-
<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>
85+
<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>
8686

8787

8888

docs/api/output/Autolinker.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/output/Autolinker.match.Url.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)