You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "pascal.barbedor@laposte.net" <pa...@laposte.net> on 2002/10/01 14:25:03 UTC

bug with IO::Scalar IO::String Text::Iconv and XML

Hi

here is a program that shows something wrong when using 
Text::Iconv with
IO::Scalar or IO::String


read a sample xml file, with an accented character, after 
xml parsing (which translates to utf-8), translate back to iso-
8859-1.

also prepare a simple utf-8 string with text::iconv


problem :
when print is done with IO::Scalar or IO::String redirection, 
conversion fails.


pascal


here the XML is read with XML::Simple or XML::LibXML, 
but this is the same with XML::XPath


note Text::Iconv->raise_error(1) raises no error.


source program test:
--------------------------------------------------------
use warnings;
use XML::Simple;
use Text::Iconv;
use XML::LibXML ;
Text::Iconv::->raise_error(1);

my $string=q{<?xml version="1.0" encoding="iso-8859-1" ?
><grp>étude</grp>};

my $string2=Text::Iconv->new("iso-8859-1","utf-8")->convert
("étude");

my $doc =XML::LibXML->new->parse_string($string) ;

my $ref=XML::Simple->new->XMLin($string);

my $C= Text::Iconv->new('UTF-8','ISO-8859-1');



print "\n------------------------------\n";
print $doc->toString, "\n raw:", $ref,"\tconv:", $C->convert
($ref);
print "\n str2:", $string2,"\tconv:", $C->convert($string2);


------------------------------------------------------



source program calltest 
-----------------------------------------------------
use IO::Scalar;
use IO::String;
  
    my $page;
    my $CACHE =new IO::Scalar \$page ;
    select $CACHE;
    do 'test' ;
    select STDOUT;
    print $page ;


    my $io=IO::String->new(my $tocache);

    select  $io ;
    do 'test' ;
    select STDOUT ;


    print $tocache ;

     do 'test' ;

----------------------------------------------------------------
-----------
output of PERL test 
----------------------------------------------------------------
--


------------------------------
<?xml version="1.0" encoding="iso-8859-1"?>
<grp>étude</grp>

 raw:étude	conv:étude
 str2:étude	conv:étude

raw print is UTF-8, conv print is iso
XML output is in iso directly
Iconv conversion is successful
raw and str2 are the same
all correct


now look at other output :

==========================================
output of PERL calltest


IO::Scalar ------------------------------

<?xml version="1.0" encoding="iso-8859-1"?>
<grp>étude</grp>

 raw:étude	conv:étude
 str2:étude	conv:étude

IO::String------------------------------

<?xml version="1.0" encoding="iso-8859-1"?>
<grp>étude</grp>

 raw:étude	conv:étude
 str2:étude	conv:étude

STDOUT------------------------------

<?xml version="1.0" encoding="iso-8859-1"?>
<grp>étude</grp>

 raw:étude	conv:étude
 str2:étude	conv:étude
=============================================


ICONV fails to convert when IO redirection,
 looks like characters are not the same between raw and 
string2, which
both should be utf-8 translation of "étude"


the toString method of LIbXML seems to output back in iso-8859-
1, without explicit
translation, but this fails with IO redirection too.




Accédez au courrier électronique de La Poste : www.laposte.net ; 3615 LAPOSTENET (0,13 €/mn) ; tél : 08 92 68 13 50 (0,34€/mn)"




Re: Daft question - preventing the username password box from appearing.

Posted by Martin Moss <Ma...@btinternet.com>.
thanks to everyone,
Geoff's post made me re-examine AuthCookie and I realised I wasn't supposed
to use the get_basic_auth_pw method at all.

Thanks I understand whats going on now.

Cheers

Marty
----- Original Message -----
From: "Lupe Christoph" <lu...@lupe-christoph.de>
To: "Martin Moss" <ma...@btinternet.com>
Cc: "modperl" <mo...@perl.apache.org>
Sent: Tuesday, October 01, 2002 3:06 PM
Subject: Re: Daft question - preventing the username password box from
appearing.


> On Tuesday, 2002-10-01 at 14:16:47 +0100, Martin Moss wrote:
>
> > I do not wish to have the prompt box appear, I want to have a
dynamically
> > produced login form which when submitted carries out the users previous
> > command (I have an authentication system which 'times out' a user)
>
> You can't in mod_perl. When you use Basic Authentication, the *browser*
> pops up the "prompt box". To change this, you have to ditch Basic Auth
> and implement something else.
>
> You best start by looking at the various "auth" packages in Apache and
> those in in Perl (Apache::.*Auth). Then consider doing this in
> Javascript or in HTML.
>
> HTH,
> Lupe Christoph
> --
> | lupe@lupe-christoph.de       |           http://www.lupe-christoph.de/ |
> | Big Misunderstandings #6398: The Titanic was not supposed to be        |
> | unsinkable. The designer had a speech impediment. He said: "I have     |
> | thith great unthinkable conthept ..."                                  |
>


Re: Daft question - preventing the username password box from appearing.

Posted by Lupe Christoph <lu...@lupe-christoph.de>.
On Tuesday, 2002-10-01 at 14:16:47 +0100, Martin Moss wrote:

> I do not wish to have the prompt box appear, I want to have a dynamically
> produced login form which when submitted carries out the users previous
> command (I have an authentication system which 'times out' a user)

You can't in mod_perl. When you use Basic Authentication, the *browser*
pops up the "prompt box". To change this, you have to ditch Basic Auth
and implement something else.

You best start by looking at the various "auth" packages in Apache and
those in in Perl (Apache::.*Auth). Then consider doing this in
Javascript or in HTML.

HTH,
Lupe Christoph
-- 
| lupe@lupe-christoph.de       |           http://www.lupe-christoph.de/ |
| Big Misunderstandings #6398: The Titanic was not supposed to be        |
| unsinkable. The designer had a speech impediment. He said: "I have     |
| thith great unthinkable conthept ..."                                  |

Re: Daft question - preventing the username password box from appearing.

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Martin Moss wrote:
> All,
> 
> How do I change the behaviour of get_basic_auth_passwd()
> 
> I do not wish to have the prompt box appear, I want to have a dynamically
> produced login form which when submitted carries out the users previous
> command (I have an authentication system which 'times out' a user)
> 
> the problem I have is that this doesn't work:-
> 
>  my $response=&timedout($r); #returns a string of html to display
>       $r->custom_response(AUTH_REQUIRED,$response);
>       return AUTH_REQUIRED;
> 
> 
> The problem is this still prompts the user for his username and password,
> and only displays the html is the user presses cancel.
> How do I ditch the login box completely?


use FORBIDDEN instead of AUTH_REQUIRED.

see recipe 13.7 in the Cookbook, or Apache::AuthCookie for examples of 
how this is done (hint, it requires a bit of fancy footwork :)

HTH

--Geoff


Daft question - preventing the username password box from appearing.

Posted by Martin Moss <Ma...@btinternet.com>.
All,

How do I change the behaviour of get_basic_auth_passwd()

I do not wish to have the prompt box appear, I want to have a dynamically
produced login form which when submitted carries out the users previous
command (I have an authentication system which 'times out' a user)

the problem I have is that this doesn't work:-

 my $response=&timedout($r); #returns a string of html to display
      $r->custom_response(AUTH_REQUIRED,$response);
      return AUTH_REQUIRED;


The problem is this still prompts the user for his username and password,
and only displays the html is the user presses cancel.
How do I ditch the login box completely?

Regards

Marty