@@ -1034,24 +1034,8 @@ Renderer.prototype.del = function(text) {
1034
1034
} ;
1035
1035
1036
1036
Renderer . prototype . link = function ( href , title , text ) {
1037
- if ( this . options . sanitize ) {
1038
- try {
1039
- var prot = decodeURIComponent ( unescape ( href ) )
1040
- . replace ( / [ ^ \w : ] / g, '' )
1041
- . toLowerCase ( ) ;
1042
- } catch ( e ) {
1043
- return text ;
1044
- }
1045
- if ( prot . indexOf ( 'javascript:' ) === 0 || prot . indexOf ( 'vbscript:' ) === 0 || prot . indexOf ( 'data:' ) === 0 ) {
1046
- return text ;
1047
- }
1048
- }
1049
- if ( this . options . baseUrl && ! originIndependentUrl . test ( href ) ) {
1050
- href = resolveUrl ( this . options . baseUrl , href ) ;
1051
- }
1052
- try {
1053
- href = encodeURI ( href ) . replace ( / % 2 5 / g, '%' ) ;
1054
- } catch ( e ) {
1037
+ href = cleanUrl ( this . options . sanitize , this . options . baseUrl , href ) ;
1038
+ if ( href === null ) {
1055
1039
return text ;
1056
1040
}
1057
1041
var out = '<a href="' + escape ( href ) + '"' ;
@@ -1063,9 +1047,11 @@ Renderer.prototype.link = function(href, title, text) {
1063
1047
} ;
1064
1048
1065
1049
Renderer . prototype . image = function ( href , title , text ) {
1066
- if ( this . options . baseUrl && ! originIndependentUrl . test ( href ) ) {
1067
- href = resolveUrl ( this . options . baseUrl , href ) ;
1050
+ href = cleanUrl ( this . options . sanitize , this . options . baseUrl , href ) ;
1051
+ if ( href === null ) {
1052
+ return text ;
1068
1053
}
1054
+
1069
1055
var out = '<img src="' + href + '" alt="' + text + '"' ;
1070
1056
if ( title ) {
1071
1057
out += ' title="' + title + '"' ;
@@ -1343,6 +1329,30 @@ function edit(regex, opt) {
1343
1329
} ;
1344
1330
}
1345
1331
1332
+ function cleanUrl ( sanitize , base , href ) {
1333
+ if ( sanitize ) {
1334
+ try {
1335
+ var prot = decodeURIComponent ( unescape ( href ) )
1336
+ . replace ( / [ ^ \w : ] / g, '' )
1337
+ . toLowerCase ( ) ;
1338
+ } catch ( e ) {
1339
+ return null ;
1340
+ }
1341
+ if ( prot . indexOf ( 'javascript:' ) === 0 || prot . indexOf ( 'vbscript:' ) === 0 || prot . indexOf ( 'data:' ) === 0 ) {
1342
+ return null ;
1343
+ }
1344
+ }
1345
+ if ( base && ! originIndependentUrl . test ( href ) ) {
1346
+ href = resolveUrl ( base , href ) ;
1347
+ }
1348
+ try {
1349
+ href = encodeURI ( href ) . replace ( / % 2 5 / g, '%' ) ;
1350
+ } catch ( e ) {
1351
+ return null ;
1352
+ }
1353
+ return href ;
1354
+ }
1355
+
1346
1356
function resolveUrl ( base , href ) {
1347
1357
if ( ! baseUrls [ ' ' + base ] ) {
1348
1358
// we can ignore everything in base after the last slash of its path component,
0 commit comments