Mailing List Archive

rt branch, 5.0/rest2-base64-encode-attachment-content, repushed
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.

_______________________________________________
rt-commit mailing list
rt-commit@lists.bestpractical.com
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-commit
rt branch, 5.0/rest2-base64-encode-attachment-content, repushed [ In reply to ]
The branch 5.0/rest2-base64-encode-attachment-content was deleted and repushed:
was e75be21c8e4bee4c7e6d535cba1b55b21ab8ad33
now 8e58a3f43d3d13ac3bdc60f44de9446f71c31b4f

1: 9976d75124 ! 1: f1724f9566 Make GET .../REST2/attachment/:id base64-encode the Content field.
@@ -25,11 +25,11 @@
+ my ($orig, $self) = @_;
+ my $data = $self->$orig(@_);
+
-+ # Encode as UTF-8 if it's textual content, OR if the raw data
++ # Encode as UTF-8 if it's an internal Perl Unicode string, or if it
+ # 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]/) {
++ # wide characters, encode_base64 will die anyway, so encoding
++ # seems like a safer choice.
++ if (utf8::is_utf8($data->{Content}) || $data->{Content} =~ /[^\x00-\xFF]/) {
+ # Encode internal Perl string to UTF-8
+ $data->{Content} = encode('UTF-8', $data->{Content}, Encode::FB_PERLQQ);
+ }
2: e75be21c8e = 2: 8e58a3f43d Document that GET /attachment/:id base64-encodes the content.

_______________________________________________
rt-commit mailing list
rt-commit@lists.bestpractical.com
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-commit