Changeset 4941


Ignore:
Timestamp:
09/15/09 21:35:59 (2 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.

Location:
trunk/WysiwygPlugin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin.pm

    r4930 r4941  
    555555 
    556556    # Look for combinations of sticky and other markup that cause problems together 
    557     for my $tag ('verbatim', 'literal', keys %xmltag) { 
     557    for my $tag ('literal', keys %xmltag) { 
    558558        while ($text =~ /<$tag\b[^>]*>(.*?)<\/$tag>/gsi) { 
    559559            my $inner = $1; 
  • trunk/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/TML2HTML.pm

    r4294 r4941  
    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; 
  • trunk/WysiwygPlugin/test/unit/WysiwygPlugin/TranslatorTests.pm

    r4930 r4941  
    16521652    }, 
    16531653    { 
    1654         exec => $ROUNDTRIP | $CANNOTWYSIWYG, # SMELL: Fix this case 
     1654        exec => $HTML2TML | $ROUNDTRIP, 
    16551655        name => 'stickyInsideVerbatimItem1980', 
    16561656        tml  => <<'GLUED', 
     
    21582158 
    21592159    my $txer = new Foswiki::Plugins::WysiwygPlugin::TML2HTML(); 
    2160     my $html = $txer->convert( 
    2161         $tml, 
    2162         $this->TML_HTMLconverterOptions() 
    2163     ); 
     2160    # This conversion can throw an exception.  
     2161    # This might be expected if $args->{exec} also has $CANNOTWYSIWYG set 
     2162    my $html = eval { 
     2163        $txer->convert( 
     2164            $tml, 
     2165            $this->TML_HTMLconverterOptions() 
     2166        ); 
     2167    }; 
     2168    $html = $@ if $@; 
    21642169 
    21652170    $txer = new Foswiki::Plugins::WysiwygPlugin::HTML2TML(); 
Note: See TracChangeset for help on using the changeset viewer.