[Rt-commit] rt branch, 4.0/ckeditor-escaping, created. rt-4.0.0rc4-24-gb5be510

Alex Vandiver alexmv at bestpractical.com
Mon Jun 20 10:23:11 EDT 2011


The branch, 4.0/ckeditor-escaping has been created
        at  b5be510c9ed7d393a3d5c668cce6210713c63067 (commit)

- Log -----------------------------------------------------------------
commit aa1589ffb6be72a81e6fd76035733a5558754697
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Jan 25 21:29:58 2011 -0500

    Make CKeditor work with the back button
    
    Using the back button caused the html-filled output of the submission
    to appear in the textarea, then be encoded _again_ by the
    ckeditor-creation code.  We work around this by inserting a
    <input type="text" style="display:none"> element into the form, which
    we update when we upgrade the field.  This serves dual purposes: it
    notifies the perl side of the content type of the field, but it also
    serves as a storage of if the text->html encoding has already happened
    in javascript.
    
    This needs to be a type="text" because, unlike text="hidden", values
    in those fields are restored to their submit-time values when the back
    button is pressed.  Thus, the only way to back this system safe from
    the back button is to store that information in a non-hidden text
    area, and hide it using CSS.

diff --git a/share/html/Elements/HeaderJavascript b/share/html/Elements/HeaderJavascript
index bc507dc..8f9159c 100644
--- a/share/html/Elements/HeaderJavascript
+++ b/share/html/Elements/HeaderJavascript
@@ -67,7 +67,7 @@ $onload => undef
 % }
 
 % if ( RT->Config->Get('MessageBoxRichText',  $session{'CurrentUser'})) {
-    jQuery().ready(function ()  { ReplaceAllTextareas('<%$m->request_args->{'CKeditorEncoded'} || 0 %>') });
+    jQuery().ready(function ()  { ReplaceAllTextareas() });
 % }
 --></script>
 
diff --git a/share/html/Elements/MessageBox b/share/html/Elements/MessageBox
index 5aff445..871a8bb 100755
--- a/share/html/Elements/MessageBox
+++ b/share/html/Elements/MessageBox
@@ -50,6 +50,9 @@
 % $m->callback( %ARGS, SignatureRef => \$signature );
 <% $Default || '' %><% $message %><% $signature %></textarea>
 % $m->callback( %ARGS, CallbackName => 'AfterTextArea' );
+% if (RT->Config->Get('MessageBoxRichText',  $session{'CurrentUser'})) {
+<input type="text" style="display:none" name="<% $Name %>Type" id="<% $Name %>Type" value="<% $m->request_args->{$Name."Type"}||'' %>" />
+% }
 <%INIT>
 
 my $message = '';
diff --git a/share/html/NoAuth/js/util.js b/share/html/NoAuth/js/util.js
index 6c926f6..0d24e5b 100644
--- a/share/html/NoAuth/js/util.js
+++ b/share/html/NoAuth/js/util.js
@@ -252,7 +252,7 @@ function textToHTML(value) {
                 .replace(/\n/g,   "\n<br />");
 };
 
-function ReplaceAllTextareas(encoded) {
+function ReplaceAllTextareas() {
     var sAgent = navigator.userAgent.toLowerCase();
     if (!CKEDITOR.env.isCompatible ||
         sAgent.indexOf('iphone') != -1 ||
@@ -267,23 +267,12 @@ function ReplaceAllTextareas(encoded) {
         var textArea = allTextAreas[i];
         if (jQuery(textArea).hasClass("messagebox")) {
             // Turn the original plain text content into HTML
-            if (encoded == 0) {
+            var type = jQuery("#"+textArea.name+"Type");
+            if (type.val() != "text/html")
                 textArea.value = textToHTML(textArea.value);
-            }
-            // For this javascript
-            var CKeditorEncoded = document.createElement('input');
-            CKeditorEncoded.setAttribute('type', 'hidden');
-            CKeditorEncoded.setAttribute('name', 'CKeditorEncoded');
-            CKeditorEncoded.setAttribute('value', '1');
-            textArea.parentNode.appendChild(CKeditorEncoded);
-
-            // For fckeditor
-            var typeField = document.createElement('input');
-            typeField.setAttribute('type', 'hidden');
-            typeField.setAttribute('name', textArea.name + 'Type');
-            typeField.setAttribute('value', 'text/html');
-            textArea.parentNode.appendChild(typeField);
 
+            // Set the type
+            type.val("text/html");
 
             CKEDITOR.replace(textArea.name,{width:'100%',height:'<% RT->Config->Get('MessageBoxRichTextHeight') %>'});
             CKEDITOR.basePath = "<%RT->Config->Get('WebPath')%>/NoAuth/RichText/";

commit b5be510c9ed7d393a3d5c668cce6210713c63067
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Jan 25 21:47:28 2011 -0500

    Make empty-message-detection happen client-side for CKeditor

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 49d8d06..c790341 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -872,39 +872,24 @@ sub StripContent {
 
     my $return_content = $content;
 
-    my $html = $args{ContentType} && $args{ContentType} eq "text/html";
-    my $sigonly = $args{StripSignature};
+    # If we aren't supposed to strip the sig, just bail now.
+    return $return_content unless $args{StripSignature};
 
-    # massage content to easily detect if there's any real content
-    $content =~ s/\s+//g; # yes! remove all the spaces
-    if ( $html ) {
-        # remove html version of spaces and newlines
-        $content =~ s!&nbsp;!!g;
-        $content =~ s!<br/?>!!g;
+    # Sig-stripping is done client-side with HTML
+    if ($args{ContentType} && $args{ContentType} eq "text/html") {
+        return "" unless $content =~ /\S/;
+        return $return_content;
     }
 
-    # Filter empty content when type is text/html
-    return '' if $html && $content !~ /\S/;
-
-    # If we aren't supposed to strip the sig, just bail now.
-    return $return_content unless $sigonly;
+    # massage content to easily detect if there's any real content
+    $content =~ s/\s+//g; # yes! remove all the spaces
 
     # Find the signature
     my $sig = $args{'CurrentUser'}->UserObj->Signature || '';
     $sig =~ s/\s+//g;
 
     # Check for plaintext sig
-    return '' if not $html and $content =~ /^(--)?\Q$sig\E$/;
-
-    # Check for html-formatted sig; we don't use EscapeUTF8 here
-    # because we want to precisely match the escapting that FCKEditor
-    # uses.
-    $sig =~ s/&/&amp;/g;
-    $sig =~ s/</&lt;/g;
-    $sig =~ s/>/&gt;/g;
-    $sig =~ s/"/&quot;/g;
-    $sig =~ s/'/&#39;/g;
-    return '' if $html and $content =~ m{^(?:<p>)?(--)?\Q$sig\E(?:</p>)?$}s;
+    return '' if $content =~ /^(--)?\Q$sig\E$/;
 
     # Pass it through
     return $return_content;
diff --git a/share/html/NoAuth/js/util.js b/share/html/NoAuth/js/util.js
index 0d24e5b..4107c40 100644
--- a/share/html/NoAuth/js/util.js
+++ b/share/html/NoAuth/js/util.js
@@ -274,9 +274,15 @@ function ReplaceAllTextareas() {
             // Set the type
             type.val("text/html");
 
-            CKEDITOR.replace(textArea.name,{width:'100%',height:'<% RT->Config->Get('MessageBoxRichTextHeight') %>'});
+            var editor = CKEDITOR.replace(textArea.name,{width:'100%',height:'<% RT->Config->Get('MessageBoxRichTextHeight') %>'});
             CKEDITOR.basePath = "<%RT->Config->Get('WebPath')%>/NoAuth/RichText/";
 
+            // When submitting, clear it out if they didn't change it from the initial sig
+            jQuery(window).unload(function(){
+                if ( !editor.checkDirty() )
+                    editor.setData('');
+            });
+
             jQuery("#" + textArea.name + "___Frame").addClass("richtext-editor");
         }
     }

-----------------------------------------------------------------------


More information about the Rt-commit mailing list