[Rt-commit] rt branch, 4.4/rest-1-attachment-raw-content, created. rt-4.4.4-95-g39a112d9d5

? sunnavy sunnavy at bestpractical.com
Mon Apr 6 13:05:22 EDT 2020


The branch, 4.4/rest-1-attachment-raw-content has been created
        at  39a112d9d520e738314f03e2df00a8d64e430c34 (commit)

- Log -----------------------------------------------------------------
commit 39a112d9d520e738314f03e2df00a8d64e430c34
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Apr 4 00:25:03 2020 +0800

    Don't touch attachment content's newlines in REST 1.0
    
    Thus people could get the real original attachment content.
    
    Fixes: I#35719

diff --git a/lib/RT/Interface/REST.pm b/lib/RT/Interface/REST.pm
index 2cd707c478..06a0bde4ad 100644
--- a/lib/RT/Interface/REST.pm
+++ b/lib/RT/Interface/REST.pm
@@ -198,8 +198,16 @@ sub form_compose {
         my $text = "";
 
         if ($c) {
-            $c =~ s/\n*$/\n/;
-            $text = "$c\n";
+
+            # $c means comments, but we also use it to render attachment
+            # contents, in which case massaging newlines is not a good idea.
+            if ( $HTML::Mason::Commands::m->notes('raw-content') ) {
+                $text = $c;
+            }
+            else {
+                $c =~ s/\n*$/\n/;
+                $text = "$c\n";
+            }
         }
         if ($e) {
             $text .= $e;
diff --git a/share/html/REST/1.0/Forms/attachment/default b/share/html/REST/1.0/Forms/attachment/default
index e4c84cfc5f..79ed8cc9fc 100644
--- a/share/html/REST/1.0/Forms/attachment/default
+++ b/share/html/REST/1.0/Forms/attachment/default
@@ -68,6 +68,7 @@ my @arglist = split( '/', $args || "" );
 my $content;
 
 if ( @arglist and $arglist[0] eq 'content' ) {
+    $m->notes( 'raw-content' => 1 );
     $c = $attachment->OriginalContent;
     $r->content_type($attachment->ContentType)
         if $attachment->ContentType !~ /^text\//;
diff --git a/share/html/REST/1.0/Forms/ticket/attachments b/share/html/REST/1.0/Forms/ticket/attachments
index 292d69185c..29b999916c 100644
--- a/share/html/REST/1.0/Forms/ticket/attachments
+++ b/share/html/REST/1.0/Forms/ticket/attachments
@@ -82,6 +82,7 @@ if ($aid) {
         return [ "# Invalid attachment id: $aid", [], {}, 1 ];
     }
     if ($content) {
+        $m->notes( 'raw-content' => 1 );
         $c = $attachment->OriginalContent;
         # if we're sending a binary attachment (and only the attachment)
         # flag it so bin/rt knows to special case it
diff --git a/share/html/REST/1.0/dhandler b/share/html/REST/1.0/dhandler
index c771f98553..9b7005a136 100644
--- a/share/html/REST/1.0/dhandler
+++ b/share/html/REST/1.0/dhandler
@@ -321,6 +321,7 @@ unshift(@output, [ join "\n", @comments ]) if @comments;
 $output = form_compose(\@output);
 
 OUTPUT:
-$m->out("RT/".$RT::VERSION ." ".$status ."\n\n$output\n") if ($output || $status !~ /^200/);
+$output .= "\n" if $output && !$m->notes('raw-content');
+$m->out("RT/".$RT::VERSION ." ".$status ."\n\n$output") if ($output || $status !~ /^200/);
 return;
 </%INIT>

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


More information about the rt-commit mailing list