Skip Menu |

This queue is for tickets about the GraphViz2 CPAN distribution.

Report information
The Basics
Id: 76459
Status: resolved
Priority: 0/
Queue: GraphViz2

People
Owner: Nobody in particular
Requestors: lee-in-berlin [...] web.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 2.01
Fixed in: (no value)



Subject: unicode bug in GraphViz2
Hi, first of all, thanks for rewriting GraphViz, which I use regularly. I've found a bug in GraphViz2 which isn't present in GraphViz. Check the two scripts attached, and execute them with with an utf8 string as first arg, e.g.: perl test_gv.pl gräm 1) For GraphViz2 to work, you have to either comment out "use open ':locale';", or comment in "no encoding;" 2) GraphViz will even automatically encode your string if needed, so "$name = encode( 'utf8', $name );" can be omitted. I haven't looked too far into the code what is creating this problem (I've been fighting with other unicode bugs all day, and now my eyes hurt), however I hope you can reproduce the bug. I'm using Perl 5.14.2 and GraphViz2 2.01. Thanks for your time. Regards, Lee
Subject: test_gv2.pl
#!/usr/bin/env perl use Modern::Perl '2012'; use GraphViz2; use open ':locale'; use Encode; my $g = GraphViz2->new(); my $name = shift; say 'before decoding: ', $name; $name = decode( 'utf8', $name ); say 'after decoding: ', $name; $name = encode( 'utf8', $name ); say 'after encoding: ', $name; #no encoding; $g->add_node(name => $name); $g->run( format => 'svg', output_file => 'test_gv2.svg' );
Subject: test_gv.pl
#!/usr/bin/env perl use Modern::Perl '2012'; use GraphViz; use open ':locale'; use Encode; my $g = GraphViz->new(); my $name = shift; say 'before decoding: ', $name; $name = decode( 'utf8', $name ); say 'after decoding: ', $name; $name = encode( 'utf8', $name ); say 'after encoding: ', $name; #no encoding; $g->add_node(name => $name); $g->as_svg('test_gv.svg');
Subject: Re: [rt.cpan.org #76459] unicode bug in GraphViz2
Date: Tue, 10 Apr 2012 15:07:00 +1000
To: bug-GraphViz2 [...] rt.cpan.org
From: Ron Savage <ron [...] savage.net.au>
Hi Lee On 10/04/12 12:57, Lee G. via RT wrote: Show quoted text
> Mon Apr 09 22:57:23 2012: Request 76459 was acted upon. > Transaction: Ticket created by randall > Queue: GraphViz2 > Subject: unicode bug in GraphViz2 > Broken in: 2.01 > Severity: (no value) > Owner: Nobody > Requestors: lee-in-berlin@web.de > Status: new > Ticket<URL: https://rt.cpan.org/Ticket/Display.html?id=76459> > > > Hi, > > first of all, thanks for rewriting GraphViz, which I use regularly. > > I've found a bug in GraphViz2 which isn't present in GraphViz. Check the > two scripts attached, and execute them with with an utf8 string as first > arg, e.g.: > > perl test_gv.pl gräm > > 1) For GraphViz2 to work, you have to either comment out "use open > ':locale';", or comment in "no encoding;" > > 2) GraphViz will even automatically encode your string if needed, so > "$name = encode( 'utf8', $name );" can be omitted. > > I haven't looked too far into the code what is creating this problem > (I've been fighting with other unicode bugs all day, and now my eyes > hurt), however I hope you can reproduce the bug. > > I'm using Perl 5.14.2 and GraphViz2 2.01. > > Thanks for your time.
Thanx for the sample files. I'm not going to make any changes to GraphViz2. Check the notes in CHANGES for V 2.00 and 2.01 to see a bit about the same struggles I went thru getting the code to work as well as it does. You are right in that removing use open ':locale'; from your demo makes my code work. That does not surprise me, since that line affects the open call which is before binmode is called. GraphViz uses IPC::Run::run which starts a separate process and hence ignores the setting of 'use open ...' in the original script. I have used IPC::Run in the distant past, and considered it for GraphViz2, but gave up trying to extract from the docs exactly what I would have to do. I believe the effect (of what I've done) is the same until someone (you!) sets an option for open which affects where I write dot's input to a file, as I mentioned above. I can see that adopting IPC::Run would (presumably) avoid that problem, but starting another process is a drawback. So, either way is adequate, but neither is perfect :-(. -- Ron Savage http://savage.net.au/ Ph: 0421 920 622
Sending the previous mail has failed. Please contact your admin, they can find more details in the logs.
Sending the previous mail has failed. Please contact your admin, they can find more details in the logs.
From: lee-in-berlin [...] web.de
Hi Ron, On Tue Apr 10 01:09:34 2012, ron@savage.net.au wrote: Show quoted text
> Thanx for the sample files. > > I'm not going to make any changes to GraphViz2. Check the notes in > CHANGES for V 2.00 and 2.01 to see a bit about the same struggles I went > thru getting the code to work as well as it does.
Unicode bugs can indead be a hassle :-/ Show quoted text
> > You are right in that removing > use open ':locale'; > from your demo makes my code work. That does not surprise me, since that > line affects the open call which is before binmode is called. > > GraphViz uses IPC::Run::run which starts a separate process and hence > ignores the setting of 'use open ...' in the original script. > > I have used IPC::Run in the distant past, and considered it for > GraphViz2, but gave up trying to extract from the docs exactly what I > would have to do. I believe the effect (of what I've done) is the same > until someone (you!) sets an option for open which affects where I write > dot's input to a file, as I mentioned above.
I think this is where the actual problem stems from. Right now, writing data to a file like that will give different results depending if the data is encoded in Perl's internal format or not. This is also why those two utf8 test cases print warnings. Show quoted text
> > I can see that adopting IPC::Run would (presumably) avoid that problem, > but starting another process is a drawback.
At the moment GraphViz2 is doing a system() call at that point, so it's just as good as IPC::Run will be. Show quoted text
> > So, either way is adequate, but neither is perfect :-(. >
I changed the code to use IPC::Run, piping the dot input straight into the graphviz command. I think Perl automatically encodes everything going to STDOUT in the proper way, so that's why it fixes the problem. As a nice side effect, the two warnings for scripts/utf8.(test\.)?pl also got fixed, so this is probably the right way to do it. Regards, Lee
Subject: unicode_bugfix.patch
--- lib/GraphViz2.pm~ 2012-04-10 23:49:10.170754211 +0200 +++ lib/GraphViz2.pm 2012-04-10 23:47:22.231951167 +0200 @@ -3,8 +3,6 @@ use strict; use warnings; -use Capture::Tiny 'capture'; - use Data::Section::Simple 'get_data_section'; use File::Temp (); @@ -12,6 +10,8 @@ use Hash::FieldHash ':all'; +use IPC::Run; + use Set::Array; use Try::Tiny; @@ -535,18 +535,9 @@ $self -> dot_input(join('', @{$self -> command -> print} ) . "}\n"); $self -> log(debug => $self -> dot_input); - # The EXLOCK option is for BSD-based systems. - - my($temp_dir) = File::Temp -> newdir('temp.XXXX', CLEANUP => 1, EXLOCK => 0, TMPDIR => 1); - my($name) = File::Spec -> catfile($temp_dir, 'graphviz2.dot'); - - open(OUT, '>', $name); - binmode OUT; - print OUT $self -> dot_input; - close OUT; + my($stdout, $stderr); - $Capture::Tiny::TIMEOUT = $timeout; - my($stdout, $stderr) = capture{system $driver, "-T$format", $name}; + IPC::Run::run([ $driver, "-T$format"], \$self -> dot_input, \$stdout, \$stderr); die $stderr if ($stderr);
Sending the previous mail has failed. Please contact your admin, they can find more details in the logs.
Hi Lee After my 1st reply to you I did not receive any more emails from RT re this ticket. If you check the log of your bug report you'll see several error msgs from RT itself, about email failing. So, sorry not to respond but I just assumed you left it there. I'm examining your patch now. I'm intrigued that the code I was using can be circumvented for a better result, so I'll probably adopt your suggestions. I'm sending this msg via RT and directly to your email address. Please let me know if you receive 1 or 2 copies. Cheers Ron
Hi Lee V 2.02 uses IPC::Run. $many x $thanx;
From: lee-in-berlin [...] web.de
On Wed Apr 18 21:38:27 2012, RSAVAGE wrote: Show quoted text
> Hi Lee > > After my 1st reply to you I did not receive any more emails from RT re > this ticket. > > If you check the log of your bug report you'll see several error msgs > from RT itself, about email failing. > > So, sorry not to respond but I just assumed you left it there. > > I'm examining your patch now. I'm intrigued that the code I was using > can be circumvented for a better result, so I'll probably adopt your > suggestions. > > I'm sending this msg via RT and directly to your email address. Please > let me know if you receive 1 or 2 copies. > > Cheers > Ron >
Hi Ron, I mailed the CPAN admins that day and received this reply: Show quoted text
> This was a temporary problem that was resolved in a few hours at the > time. It should no longer be the case (note the dates on the > transactions). Let us know if you have further issues.
So all should be well for now. I did receive two copies. I'm glad to see that you liked my patch and adopted it. I'm upgrading to GraphViz2 2.02 now :) Have a nice weekend! Greets, Lee
Agghhhh. Just closing it after Lee's email opened it.