Ignore:
Timestamp:
09/15/09 21:30:53 (3 years ago)
Author:
MichaelTempest
Message:

Item1980: Fix the sticky-inside-verbatim case by noting that there is no need to encode the characters for $TT0, $TT1 and TT2 - they should all be removed by the end of the conversion.

Added an explicit check to ensure that there are no more of $TT0, $TT1 and $TT2 after conversion to HTML completes, and throw an exception if it there is. That gives users a chance to save their work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Release01x00/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/TML2HTML.pm

    r4294 r4940  
    3636 
    3737use CGI qw( -any ); 
     38use Error qw( :try ); 
    3839 
    3940use Foswiki; 
     
    101102    # Substitute back in protected elements 
    102103    $content = $this->_dropBack($content); 
     104 
     105    if ($content =~ /[$TT0$TT1$TT2]/o) { 
     106        # There should never be any of these in the text at this point. 
     107        # If there are, then the conversion failed.  
     108        # Encode the original TML as verbatim-style HTML and include it 
     109        # in an error log, so that the user at least has a chance to save 
     110        # his/her work. 
     111        my $originalContent = $_[1]; 
     112        $originalContent =~ s/[$TT0$TT1$TT2]/?/go; 
     113        $originalContent = _protectVerbatimChars($originalContent); 
     114        $originalContent =~ s{/}{'&#'.ord('/').';'}ge; # </tag> looks like a path, but it isn't 
     115        throw Error::Simple( 'Conversion to HTML failed. TML:<br />'.$originalContent ); 
     116    } 
    103117 
    104118    # DEBUG 
     
    538552sub _protectVerbatimChars { 
    539553    my $text = shift; 
    540     $text =~ s/([\000-\011\013-\037<&>'"])/'&#'.ord($1).';'/ges; 
     554    # $TT0, $TT1 and $TT2 are chr(0), chr(1) and chr(2), respectively.  
     555    # They are handled specially, elsewhere 
     556    $text =~ s/([\003-\011\013-\037<&>'"])/'&#'.ord($1).';'/ges; 
    541557    $text =~ s/ /&nbsp;/g; 
    542558    $text =~ s/\n/<br \/>/gs; 
Note: See TracChangeset for help on using the changeset viewer.