-
-
Save anonymous/cdde4a8ee97c6d42f659 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Mojo/Message.pm b/lib/Mojo/Message.pm | |
index e5f0f86..53b559d 100644 | |
--- a/lib/Mojo/Message.pm | |
+++ b/lib/Mojo/Message.pm | |
@@ -188,7 +188,7 @@ sub start_line_size { length shift->build_start_line } | |
sub text { | |
my $self = shift; | |
my $body = $self->body; | |
- my $charset = $self->content->charset; | |
+ my $charset = $self->content->charset || $self->default_charset; | |
return $charset ? decode($charset, $body) // $body : $body; | |
} | |
@@ -219,8 +219,7 @@ sub uploads { | |
sub _build { | |
my ($self, $method) = @_; | |
- my $buffer = ''; | |
- my $offset = 0; | |
+ my ($buffer, $offset) = ('', 0); | |
while (1) { | |
# No chunk yet, try again | |
@@ -622,8 +621,8 @@ Size of the start-line in bytes. | |
my $str = $msg->text; | |
-Retrieve L</"body"> and try to decode it if a charset could be extracted with | |
-L<Mojo::Content/"charset">. | |
+Retrieve L</"body"> and try to decode it with L<Mojo::Content/"charset"> or | |
+L</"default_charset">. | |
=head2 to_string | |
diff --git a/t/mojo/response.t b/t/mojo/response.t | |
index 6b593cc..820bcc9 100644 | |
--- a/t/mojo/response.t | |
+++ b/t/mojo/response.t | |
@@ -991,6 +991,7 @@ is $res->body('hello!')->body, 'hello!', 'right content'; | |
$res->content(Mojo::Content::MultiPart->new); | |
$res->body('hi!'); | |
is $res->body, 'hi!', 'right content'; | |
+is $res->body(encode('UTF-8', '☃'))->text, '☃', 'right content'; | |
my $yatta = encode 'shift_jis', 'やった'; | |
is $res->body($yatta)->text, $yatta, 'right content'; | |
$res->headers->content_type('text/plain;charset=shift_jis'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment