summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Allbery <rra@cpan.org>2022-01-16 12:37:15 -0800
committerRuss Allbery <rra@cpan.org>2022-01-16 12:37:15 -0800
commit3fc9ec55da2fdcb1788aca3954f7b062e8855cbc (patch)
treea478fab5e52d1d1c9d1b74f83a347b6eddc4c37e
parente20f8a8ea9be76b6b506a346bc282fbad94ea7fb (diff)
Fix Unicode handling in thread output
Fix Unicode handling in App::DocKnot::Spin::Thread methods. Output to files was handled correctly in most cases, but output to a scalar or to standard output was not, nor was output to a file when the input was generated by another program.
-rw-r--r--Changes5
-rw-r--r--lib/App/DocKnot/Spin/Thread.pm15
2 files changed, 13 insertions, 7 deletions
diff --git a/Changes b/Changes
index 08856cd..a5bbcdf 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,11 @@
6.02 - Not Released
+ - Fix Unicode handling in App::DocKnot::Spin::Thread methods. Output to
+ files was handled correctly in most cases, but output to a scalar or to
+ standard output was not, nor was output to a file when the input was
+ generated by another program.
+
- Fix processing of old-style pointers in docknot spin.
- Fix import error when running docknot release.
diff --git a/lib/App/DocKnot/Spin/Thread.pm b/lib/App/DocKnot/Spin/Thread.pm
index 0d84bd7..0e55b9e 100644
--- a/lib/App/DocKnot/Spin/Thread.pm
+++ b/lib/App/DocKnot/Spin/Thread.pm
@@ -13,10 +13,11 @@ package App::DocKnot::Spin::Thread 6.01;
use 5.024;
use autodie;
-use warnings;
+use warnings FATAL => 'utf8';
use App::DocKnot;
use App::DocKnot::Util qw(print_fh);
+use Encode qw(decode);
use Git::Repository ();
use Image::Size qw(html_imgsize);
use Path::Tiny qw(path);
@@ -1467,10 +1468,10 @@ sub new {
sub spin_thread {
my ($self, $thread, $input) = @_;
my $result;
- open(my $out_fh, '>', \$result);
+ open(my $out_fh, '>:raw:encoding(utf-8)', \$result);
$self->_parse_document($thread, $input, $out_fh, undef);
close($out_fh);
- return $result;
+ return decode('utf-8', $result);
}
# Spin a single file of thread to HTML.
@@ -1497,7 +1498,7 @@ sub spin_thread_file {
$output = path($output)->absolute();
$out_fh = $output->openw_utf8();
} else {
- open($out_fh, '>&', 'STDOUT');
+ open($out_fh, '>&:raw:encoding(utf-8)', 'STDOUT');
}
# Do the work.
@@ -1526,9 +1527,9 @@ sub spin_thread_output {
my $out_fh;
if (defined($output)) {
$output = path($output)->absolute();
- $out_fh = $output->filehandle('>');
+ $out_fh = $output->openw_utf8();
} else {
- open($out_fh, '>&', 'STDOUT');
+ open($out_fh, '>&:raw:encoding(utf-8)', 'STDOUT');
}
# Do the work.
@@ -2097,7 +2098,7 @@ Russ Allbery <rra@cpan.org>
=head1 COPYRIGHT AND LICENSE
-Copyright 1999-2011, 2013, 2021 Russ Allbery <rra@cpan.org>
+Copyright 1999-2011, 2013, 2021-2022 Russ Allbery <rra@cpan.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal