Changeset 427

Show
Ignore:
Timestamp:
2007-07-09 13:33:08 (3 years ago)
Author:
martinkou
Message:

Fixed #268 : A more robust encoding/decoding algorithm for protecting event attributes has been implemented, which guarantees JavaScript code within event attributes would be converted correctly when switching to and from source view.

Location:
FCKeditor/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor/trunk/editor/_source/internals/fck.js

    r425 r427  
    698698function _FCK_ProtectEvents_ReplaceEvents( eventMatch, attName ) 
    699699{ 
    700         return ' ' + attName + '_fckprotectedatt="' + eventMatch.ReplaceAll( [/&/g,/'/g,/"/g,/=/g,/</g,/>/g,/\r/g,/\n/g], ['&apos;','&#39;','&quot;','&#61;','&lt;','&gt;','&#10;','&#13;'] ) + '"' ; 
     700        return ' ' + attName + '_fckprotectedatt="' + FCKTools.EncodeToHex( eventMatch ) + '"' ; 
    701701} 
    702702 
    703703function _FCK_ProtectEvents_RestoreEvents( match, encodedOriginal ) 
    704704{ 
    705         return encodedOriginal.ReplaceAll( [/&#39;/g,/&quot;/g,/&#61;/g,/&lt;/g,/&gt;/g,/&#10;/g,/&#13;/g,/&apos;/g], ["'",'"','=','<','>','\r','\n','&'] ) ; 
     705        return FCKTools.DecodeHex( encodedOriginal ) ; 
    706706} 
    707707 
  • FCKeditor/trunk/editor/_source/internals/fcklistslib.js

    r308 r427  
    5757                else 
    5858                        this.PathBlockLimitElements.div = 1 ; 
    59         } 
     59        }, 
     60 
     61        HexList : [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" ], 
     62 
     63        HexMap : { "0":0, "1":1, "2":2, "3":3, "4":4, "5":5, "6":6, "7":7, "8":8, "9":9, "A":10, 
     64                "B":11, "C":12, "D":13, "E":14, "F":15 }  
    6065} ; 
  • FCKeditor/trunk/editor/_source/internals/fcktools.js

    r414 r427  
    416416        return null ; 
    417417} 
     418 
     419FCKTools.EncodeToHex = function( str ) 
     420{ 
     421        var symbols = FCKListsLib.HexList ; 
     422        var output = [] ; 
     423        // assume code points are 16-bits 
     424        for ( var i = 0 ; i < str.length ; i++ ) 
     425        { 
     426                var c = str.charCodeAt( i ) ; 
     427                var lsn = c & 0x000f ; 
     428                var second = ( c & 0x00f0 ) >> 4 ; 
     429                var third = ( c & 0x0f00 ) >> 8 ; 
     430                var msn = ( c & 0xf000 ) >> 12 ; 
     431                output.push( [ symbols[msn], symbols[third], symbols[second], symbols[lsn] ].join( "" ) ) ; 
     432        } 
     433        return output.join( "" ) ; 
     434} 
     435 
     436FCKTools.DecodeHex = function( hexstr ) 
     437{ 
     438        if ( hexstr.length % 4 != 0 ) 
     439                throw "FCKTools.DecodeHex(): hexstr length must be multiple of 4." ; 
     440 
     441        var symbols = FCKListsLib.HexMap ; 
     442        var output = [] ; 
     443        for ( var i = 0 ; i < hexstr.length ; i+=4 ) 
     444        { 
     445                var codePoint = symbols[ hexstr[i] ] << 12 ; 
     446                codePoint |= symbols[ hexstr[ i + 1 ] ] << 8 ; 
     447                codePoint |= symbols[ hexstr[ i + 2 ] ] << 4 ; 
     448                codePoint |= symbols[ hexstr[ i + 3 ] ] ; 
     449                output.push( String.fromCharCode( codePoint ) ) ; 
     450        } 
     451        return output.join( "" ) ; 
     452} 
  • FCKeditor/trunk/_whatsnew.html

    r423 r427  
    106106                [<a target="_blank" href="http://dev.fckeditor.net/ticket/932">#932</a>] Clicking outside the editor it was possible 
    107107                        to paste or apply formating to the rest of the page in IE.</li> 
     108                <li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/137">#137</a>] Fixed FCKConfig.TabSpaces being ignored, 
     109                        and weired behaviors when pressing tab in edit source mode.</li> 
     110                <li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/268">#268</a>] Fixed special XHTML characters present  
     111                        in event attribute values being converted inappropriately when switching to source view.</li> 
    108112        </ul> 
    109113        <h3>