FAQ
I had a problem and was wondering whether my solution was any good:

* Problem *
In the browser, I enter "Lindstr?m" in a name field and save it to the
database.

In the view template this value looks nice:
[% item.$column | html %] --> Lindstr?m

In the form, as the value of an input element, in the edit template, the
value looks weird, with ? being rendered as two chars (the multi-byte utf8
char presumably):
[% item.to_field(column).as_HTML %] --> <input type="text"
value="Lindstr??"m">

The browser uses utf-8 from the HTTP header (and/or the <meta> content
type, but it doesn't seem to matter that much). That's not a problem.

In SQLite I can see the double char when looking at the table with dbish,
but Perl seems to handle that correctly, because the ? is there in the
variable value when I look at it.

Class::DBI::AsForm emits HTML::Element objects. The problem seems to be
HTML::Element's as_HTML method which calls
HTML::Entities::encode_entities() and interprets the ? as two chars.


* Solution *
My solution was to explicitly leave everything alone, except for the
"normal" HTML chars:
[% item.to_field(column).as_HTML('<>&"\'') %] --> Lindstr?m


Now... is this a good solution? The right place to solve it? Is it the
right thing?


/J

Search Discussions

  • Mikhail Shevchuk at Nov 28, 2005 at 11:42 am

    On Mon, Nov 28, 2005 at 11:05:58AM +0100, Johan Lindstr?m wrote:
    Class::DBI::AsForm emits HTML::Element objects. The problem seems to be
    HTML::Element's as_HTML method which calls
    HTML::Entities::encode_entities() and interprets the ? as two chars.
    This happend not only with utf chars, but even with some 8-byte
    characters. For example with cyrillic koi8-r. I've written about this in
    thread Class::DBI::AsForm.
    My solution was to explicitly leave everything alone, except for the
    "normal" HTML chars:
    [% item.to_field(column).as_HTML('<>&"\'') %] --> Lindstr?m
    I had the same idea and that worked.
  • Aristotle Pagaltzis at Nov 28, 2005 at 5:45 pm

    * Johan Lindstr?m [2005-11-28 11:20]:
    Class::DBI::AsForm emits HTML::Element objects. The problem
    seems to be HTML::Element's as_HTML method which calls
    HTML::Entities::encode_entities() and interprets the ? as two
    chars.
    Sounds like the string was never marked as Unicode to begin with,
    in which case encode_entities() sees the two bytes as two
    characters.

    Questions to investigate:

    1. Is the input string a Unicode or 8-bit string?

    2. Is the string that comes back from SQLite a Unicode or 8-bit
    string?

    3. If the string that comes back from SQLite is a Unicode string,
    is it double-encoded, or is it correct?

    Regards,
    --
    Aristotle Pagaltzis // <http://plasmasturm.org/>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedNov 28, '05 at 11:05a
activeNov 28, '05 at 5:45p
posts3
users3
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2021 Grokbase