[Rt-commit] rt branch, 5.0/rest2-base64-encode-attachment-content, repushed
Dianne Skoll
dianne at bestpractical.com
Wed Oct 21 14:39:12 EDT 2020
The branch 5.0/rest2-base64-encode-attachment-content was deleted and repushed:
was 23dd808d8ba1308162d87c71e3b450f3a7f9928d
now e75be21c8e4bee4c7e6d535cba1b55b21ab8ad33
1: 1da2bc8059 ! 1: 9976d75124 Make GET .../REST2/attachment/:id base64-encode the Content field.
@@ -10,6 +10,8 @@
use warnings;
+use MIME::Base64;
++use RT::I18N;
++use Encode;
+
use Moose;
use namespace::autoclean;
@@ -22,6 +24,15 @@
+around 'serialize' => sub {
+ my ($orig, $self) = @_;
+ my $data = $self->$orig(@_);
++
++ # Encode as UTF-8 if it's textual content, OR if the raw data
++ # contains wide characters. If the raw data does indeed contain
++ # wide characters, encode_base64 will die anyway
++ if (RT::I18N::IsTextualContentType($self->record->ContentType) ||
++ $data->{Content} =~ /[^\x00-\xFF]/) {
++ # Encode internal Perl string to UTF-8
++ $data->{Content} = encode('UTF-8', $data->{Content}, Encode::FB_PERLQQ);
++ }
+ $data->{Content} = encode_base64($data->{Content}) if defined($data->{Content});
+ return $data;
+};
@@ -50,12 +61,22 @@
is($content->{ContentType}, 'text/plain');
}
+ # Ticket Comment
+ {
+ my $payload = {
+- Content => '<i>(hello secret camera)</i>',
++ Content => "<i>(hello secret camera \x{5e9}\x{5dc}\x{5d5}\x{5dd})</i>",
+ ContentType => 'text/html',
+ Subject => 'shh',
+ TimeTaken => 129,
@@
is($res->code, 200);
$content = $mech->json_response;
is($content->{Subject}, 'shh');
- is($content->{Content}, '<i>(hello secret camera)</i>');
-+ is($content->{Content}, encode_base64('<i>(hello secret camera)</i>'));
++
++ # Note below: D7 A9 is the UTF-8 encoding of U+5E9, etc.
++ is($content->{Content}, encode_base64("<i>(hello secret camera \xD7\xA9\xD7\x9C\xD7\x95\xD7\x9D)</i>"));
is($content->{ContentType}, 'text/html');
}
2: 23dd808d8b = 2: e75be21c8e Document that GET /attachment/:id base64-encodes the content.
More information about the rt-commit
mailing list