Ticket #4963: 4963.patch

File 4963.patch, 5.5 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/link/dialogs/link.js

     
    6969        };
    7070
    7171        // Loads the parameters in a selected link to the link dialog fields.
    72         var emailRegex = /^mailto:([^?]+)(?:\?(.+))?$/,
     72        var javascriptProtocolRegex = /^javascript:/,
     73                emailRegex = /^mailto:([^?]+)(?:\?(.+))?$/,
    7374                emailSubjectRegex = /subject=([^;?:@&=$,\/]*)/,
    7475                emailBodyRegex = /body=([^;?:@&=$,\/]*)/,
    7576                anchorRegex = /^#(.*)$/,
    76                 urlRegex = /^(?!javascript)((?:http|https|ftp|news):\/\/)?(.*)$/,
     77                urlRegex = /^((?:http|https|ftp|news):\/\/)?(.*)$/,
    7778                selectableTargets = /^(_(?:self|top|parent|blank))$/,
    7879                encodedEmailLinkRegex = /^javascript:void\(location\.href='mailto:'\+String\.fromCharCode\(([^)]+)\)(?:\+'(.*)')?\)$/,
    7980                functionCallProtectedEmailLinkRegex = /^javascript:([^(]+)\(([^)]+)\)$/;
     
    8586        var parseLink = function( editor, element )
    8687        {
    8788                var href = element ? ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) : '',
     89                        javascriptMatch,
    8890                        emailMatch,
    8991                        anchorMatch,
    9092                        urlMatch,
    9193                        retval = {};
    9294
    93                 if ( ( anchorMatch = href.match( anchorRegex ) ) )
     95                if( javascriptMatch = href.match( javascriptProtocolRegex ) )
    9496                {
    95                         retval.type = 'anchor';
    96                         retval.anchor = {};
    97                         retval.anchor.name = retval.anchor.id = anchorMatch[1];
    98                 }
    99                 // urlRegex matches empty strings, so need to check for href as well.
    100                 else if ( href && ( urlMatch = href.match( urlRegex ) ) )
    101                 {
    102                         retval.type = 'url';
    103                         retval.url = {};
    104                         retval.url.protocol = urlMatch[1];
    105                         retval.url.url = urlMatch[2];
    106                 }
    107                 // Protected email link as encoded string.
    108                 else if ( !emailProtection || emailProtection == 'encode' )
    109                 {
    11097                        if( emailProtection == 'encode' )
    11198                        {
    11299                                href = href.replace( encodedEmailLinkRegex,
     
    117104                                                               ( rest && unescapeSingleQuote( rest ) );
    118105                                                } );
    119106                        }
    120 
    121                         emailMatch = href.match( emailRegex );
    122 
    123                         if( emailMatch )
    124                         {
    125                                 var subjectMatch = href.match( emailSubjectRegex ),
    126                                         bodyMatch = href.match( emailBodyRegex );
    127 
    128                                 retval.type = 'email';
    129                                 var email = ( retval.email = {} );
    130                                 email.address = emailMatch[ 1 ];
    131                                 subjectMatch && ( email.subject = decodeURIComponent( subjectMatch[ 1 ] ) );
    132                                 bodyMatch && ( email.body = decodeURIComponent( bodyMatch[ 1 ] ) );
    133                         }
    134                 }
    135                 // Protected email link as function call.
    136                 else if( emailProtection )
    137                 {
    138                         href.replace( functionCallProtectedEmailLinkRegex, function( match, funcName, funcArgs )
    139                         {
    140                                 if( funcName == compiledProtectionFunction.name )
    141                                 {
    142                                         retval.type = 'email';
    143                                         var email = retval.email = {};
     107                        // Protected email link as function call.
     108                        else if( emailProtection )
     109                        {
     110                                href.replace( functionCallProtectedEmailLinkRegex, function( match, funcName, funcArgs )
     111                                {
     112                                        if( funcName == compiledProtectionFunction.name )
     113                                        {
     114                                                retval.type = 'email';
     115                                                var email = retval.email = {};
    144116
    145                                         var paramRegex = /[^,\s]+/g,
    146                                                 paramQuoteRegex = /(^')|('$)/g,
    147                                                 paramsMatch = funcArgs.match( paramRegex ),
    148                                                 paramsMatchLength = paramsMatch.length,
    149                                                 paramName,
    150                                                 paramVal;
     117                                                var paramRegex = /[^,\s]+/g,
     118                                                        paramQuoteRegex = /(^')|('$)/g,
     119                                                        paramsMatch = funcArgs.match( paramRegex ),
     120                                                        paramsMatchLength = paramsMatch.length,
     121                                                        paramName,
     122                                                        paramVal;
    151123
    152                                         for ( var i = 0; i < paramsMatchLength; i++ )
    153                                         {
    154                                                 paramVal = decodeURIComponent( unescapeSingleQuote( paramsMatch[ i ].replace( paramQuoteRegex, '' ) ) );
    155                                                 paramName = compiledProtectionFunction.params[ i ].toLowerCase();
    156                                                 email[ paramName ] = paramVal;
    157                                         }
    158                                         email.address = [ email.name, email.domain ].join( '@' );
    159                                 }
    160                         } );
    161                 }
    162                 else
    163                         retval.type = 'url';
     124                                                for ( var i = 0; i < paramsMatchLength; i++ )
     125                                                {
     126                                                        paramVal = decodeURIComponent( unescapeSingleQuote( paramsMatch[ i ].replace( paramQuoteRegex, '' ) ) );
     127                                                        paramName = compiledProtectionFunction.params[ i ].toLowerCase();
     128                                                        email[ paramName ] = paramVal;
     129                                                }
     130                                                email.address = [ email.name, email.domain ].join( '@' );
     131                                        }
     132                                } );
     133                        }
     134                }
     135
     136                if( !retval.type )
     137                {
     138                        if ( ( anchorMatch = href.match( anchorRegex ) ) )
     139                        {
     140                                retval.type = 'anchor';
     141                                retval.anchor = {};
     142                                retval.anchor.name = retval.anchor.id = anchorMatch[1];
     143                        }
     144                        // Protected email link as encoded string.
     145                        else if ( emailMatch = href.match( emailRegex ) )
     146                        {
     147                                var subjectMatch = href.match( emailSubjectRegex ),
     148                                        bodyMatch = href.match( emailBodyRegex );
     149
     150                                retval.type = 'email';
     151                                var email = ( retval.email = {} );
     152                                email.address = emailMatch[ 1 ];
     153                                subjectMatch && ( email.subject = decodeURIComponent( subjectMatch[ 1 ] ) );
     154                                bodyMatch && ( email.body = decodeURIComponent( bodyMatch[ 1 ] ) );
     155                        }
     156                        // urlRegex matches empty strings, so need to check for href as well.
     157                        else if (  href && ( urlMatch = href.match( urlRegex ) ) )
     158                        {
     159                                retval.type = 'url';
     160                                retval.url = {};
     161                                retval.url.protocol = urlMatch[1];
     162                                retval.url.url = urlMatch[2];
     163                        }
     164                        else
     165                                retval.type = 'url';
     166                }
    164167
    165168                // Load target and popup settings.
    166169                if ( element )
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy