in reply to Decode umlauts on CGI-parameters

I store the text in db like this: "Benutzer%20l%26ouml%3Bschen" (uriescaped_utf8), when I receive it, I uriunescape it and then I compare...
It looks like the value stored in the database contains a HTML Entity, so when you retrieve and uri_unescape it, it is "Benutzer löschen", not "Benutzer löschen".
uri_unescape( Benutzer%20l%26ouml%3Bschen ) => Benutzer löschen and uri_escape( Benutzer löschen ) => Benutzer%20l%F6schen uri_escape( Benutzer löschen ) => Benutzer%20l%26ouml%3Bschen
It looks correct when you print it out to the browser, but if you view the source of the HTML you will see the problem.

One way to solve it is to html decode the value before making the comparison:

use URI::Escape; use HTML::Entities; my $db_value = uri_unescape( $aText{'1530'} ); decode_entities( $db_value ); if ( $p_sAction eq $db_value ) { ...
In the future, when you are saving the values to the database, you could remove the entities before uri_escape.

Update: minor edits.

Replies are listed 'Best First'.
Re^2: Decode umlauts on CGI-parameters
by Yaerox (Scribe) on Jul 17, 2015 at 08:23 UTC
    I need some time to finish what I'm actual doing here, then I'll take a look again on this. Thanks for the reply, I'll update this later.
    Update: Thank yo uvery much sir, this fixed it for me. I need to see if I can edit this data-storage after finishing this profect for the first.
    my $p_sAction = $oCGI->param( "action" ); if ( !defined( $p_sAction ) ){ #do stuff } $p_sAction = decode( 'UTF-8', $p_sAction ); $aText{'1510'} = decode_entities($aText{'1510'}); if ( $p_sAction eq $aText{'1460'} ){ #do stuff - NOW IT MATCHES correctly }