Loading ...
Sorry, an error occurred while loading the content.

2220Re: saving decoded unicode value to Session causes error

Expand Messages
  • Tsirkin Evgeny
    Aug 30, 2007
    • 0 Attachment
      Hi Richard!
      First of all i need to apologize:
      It is possible that i gave you a bad advice.
      I am not a Apache::ASP developer, just a user that is monitoring the list
      to follow the development (if any is making place ,i hope :) ) and
      I have tried to help  .As NOT a developer i hope it is allowed for me to make
      mistakes.

      I will try to explain :
      If you setup your server and/or application to send the header saying that the
      data is utf8 encoded then what you get from client will also be utf8 encoded.
      That IS right .So,if you just use
      $Request->Form()
      to get the data posted you will get the utf8 encoded data and you probably
      WILL be fine ,the same as i have said in the prev. reply.
      However there IS a problem:
      The string you will get from $Request object although utf8 encoded will NOT be
      marked as utf8 encoded .In other words - you get the data fine and if you for example
      store it in DBMS you are fine,but perl does not know that it is utf8 encoded.For
      perl the data is just an array of bytes
      Why does it matter for perl to mark strings as utf8?If you try to use regular expr.
      or some string functions (like length ,i think) it may not work because perl will
      assume to be character 8 bit long which not always true for utf8.
      So ,my advise of just NOT using Encode::decode_utf8 may cause actually problems
      if you try to do some processing on the data you get.
      Actually, i personally do exactly what i have advised to you :
      Taking the data just like i get it from $Request and store it.
      In the rare cases when i need to do some processing one the localized
      data (like regular expressions match ) i am marking it as utf8.


      > Hmm, I thought that perhaps it was something with Apache::ASP, and
      > that SDBM_File would be a dependency that was being passed bad data?

      I have made a test and it worked just fine,here is the code:
         <html>
      <head>
      </head>
      <body>
      <form action="" method=post>
      <input type=text name=v>
      <input type=submit>
      </form>
      </body>
      </html>
      <%

          use Encode;
      my $v=Encode::decode_utf8($Request->Form('v'));
      $Session->{v}=$v;
      print $Session->{v};
      %>
      I am also using SDBM_File  .Thought i am obviously have another version of perl :(
      Why i think that this an SDBM issue?
      The error you are getting :
      "Wide character in subroutine entry"
      means that you are trying to output/call function with wide utf8 character
      while this file handler is not setup to get this kind of data .
      A quick google search for "MLDBM utf8" approves this. :(
      So i guess you need a workaround or just try to use another DBM.

      > I suppose I misunderstood the purpose of this <meta> tag...so not
      > only output, but inputs get encoded as UTF-8 here?  Cool stuff....

      Sometimes the meta tag get ignored and you need the header,also make sure your
      server does not send such a header by his own (Apache sometimes does).

      > When, then, would I need to use decode_utf8?  I suppose it's for file-
      > reading or command-line input then?

      If you need perl to know it is  utf8  ,such as some of string manipulations.
      Again,You may also try another DBM ,change your StateDB setting .
      Maybe this is the best solution .
      Evgeny.

    • Show all 4 messages in this topic