Giter Site home page Giter Site logo

Comments (6)

kentfredric avatar kentfredric commented on August 28, 2024

Couldn't tell if this is a new bug, or the same bug:

Can't decode ill-formed UTF-8 octet sequence <E9> in position 5623 at /home/kent/perl5/perlbrew/perls/perl-5.19.5/lib/site_perl/5.19.5/Path/Tiny.pm line 679.
Can't decode ill-formed UTF-8 octet sequence <E9> in position 10096 at /home/kent/perl5/perlbrew/perls/perl-5.19.5/lib/site_perl/5.19.5/Path/Tiny.pm line 679.

This annoying, because its cropping up in the midst of processing several hundred files, and I have no idea which file the warning is pertaining to.

R-ing the source says its not any underlying mechanisms job to report this, because the underlying mechanisms aren't dealing with files at all, they only deal with the bytes.

So it makes sense its Path::Tiny's job to add filename context to this warning, ... though how to do that is anyones guess.

from path-tiny.

 avatar commented on August 28, 2024

Could you please tell me more about what you're processing: i.e. how and why? I'd like to better understand some use cases before deciding on what Path::Tiny should do.

from path-tiny.

kentfredric avatar kentfredric commented on August 28, 2024

I'm just interating the contents of Dist/Zilla/Plugin/* , oddly enough, seems the problem is Test::Compile, specificially, Test::Compile has a =pod section in ISO-8859-1

https://metacpan.org/source/ETHER/Dist-Zilla-Plugin-Test-Compile-2.037/lib/Dist/Zilla/Plugin/Test/Compile.pm#L198

from path-tiny.

chansen avatar chansen commented on August 28, 2024

Unicode::UTF8 supports fallbacks for encode_utf8() and decode_utf8() where you can report any warnings or throw exceptions.

Example:

diff --git a/lib/Path/Tiny.pm b/lib/Path/Tiny.pm
index c914332..32a343a 100644
--- a/lib/Path/Tiny.pm
+++ b/lib/Path/Tiny.pm
@@ -1137,7 +1137,24 @@ sub slurp_raw { $_[1] = { binmode => ":unix" }; goto &slurp }

 sub slurp_utf8 {
     if ( defined($HAS_UU) ? $HAS_UU : $HAS_UU = _check_UU() ) {
-        return Unicode::UTF8::decode_utf8( slurp( $_[0], { binmode => ":unix" } ) );
+        my $path = $_[0]->[PATH];
+        my $fallback = sub {
+            my ($octets, $usv, $position) = @_;
+
+            my $msg;
+            if ($usv) {
+                $msg = sprintf "Can't interchange noncharacter code point U+%X in file '%s' at position %d",
+                    $usv, $path, $position;
+            }
+            else {
+                $msg = sprintf "Can't decode ill-formed UTF-8 octet sequence <%s> in file '%s' at position %d",
+                    join(' ', map { sprintf '%.2X', ord } split //, $octets), $path, $position;
+            }
+            Carp::carp($msg);
+            return "\x{FFFD}";
+        };
+        no warnings 'utf8';
+        return Unicode::UTF8::decode_utf8( slurp( $_[0], { binmode => ":unix" } ), $fallback);
     }
     else {
         $_[1] = { binmode => ":raw:encoding(UTF-8)" };

Would output:

 $ perl -Mlib=lib -MPath::Tiny -wle 'path("~/dev/bad")->slurp_utf8;'
Can't decode ill-formed UTF-8 octet sequence <EF BF> in file '/Users/chansen/dev/bad' at position 4 at -e line 1

from path-tiny.

ilmari avatar ilmari commented on August 28, 2024

PerlIO::encoding takes its fallback behaviour from the value of $PerlIO::encoding::fallback when the layer is applied, so you can set that to one of the Encoding::FB_* values.

from path-tiny.

xdg avatar xdg commented on August 28, 2024

On reflection, I'm going to close this "won't fix". Users can disable warnings in various ways if as a Tiny module, I don't think it's the right move to add callback overhead handling malformed characters.

from path-tiny.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.