"Error : URIError: malformed URI sequence"

457 views
Skip to first unread message

Jesus Boadas

unread,
Jan 21, 2014, 3:56:23 PM1/21/14
to haxe...@googlegroups.com
js target is failing to unserialize a remote object with non ascii characters, with the error "Error : URIError: malformed URI sequence", there is a way to force utf8 decode ?

Thanks

Jesus Boadas

unread,
Jan 21, 2014, 9:07:08 PM1/21/14
to haxe...@googlegroups.com
the urlencode in the serializer doesn't complain but the urldecode do with the following characters :
ñ Ñ ¬ ° á é í ó ú Á É Í Ó Ú ¡ Ü ¨ ü

Sam MacPherson

unread,
Jan 21, 2014, 9:15:52 PM1/21/14
to haxe...@googlegroups.com
What are you using to serialize/unserialize?

Jesus Boadas

unread,
Jan 21, 2014, 9:27:48 PM1/21/14
to haxe...@googlegroups.com
I have a shared js,php object like that

class table1 #if php extends Object #end
{
    public var a : SString<36>;
    public var b : SString<30>;
    public var c :SString<30>;
    public var d :SString<2>;
   
    #if php
    public static var manager = new Manager<table1>(table1);
    #end   

    function hxSerialize( s : haxe.Serializer ) {
        s.serialize(a);
        s.serialize(b);
        s.serialize(c);
        s.serialize(d);
    }
    function hxUnserialize( s : haxe.Unserializer ) {
        a = s.unserialize();
        b = s.unserialize();
        c = s.unserialize();
        d = s.unserialize();
    }
}

also tested StringTools htmlEscape/htmlUnscape but still complain at runtime with malformed URI

Nicolas Cannasse

unread,
Jan 22, 2014, 5:53:11 AM1/22/14
to haxe...@googlegroups.com
Le 22/01/2014 03:27, Jesus Boadas a écrit :
> I have a shared js,php object like that
>
> class table1 #if php extends Object #end
> {
> public var a : SString<36>;
> public var b : SString<30>;
> public var c :SString<30>;
> public var d :SString<2>;
>
> #if php
> public static var manager = new Manager<table1>(table1);
> #end
>
> function hxSerialize( s : haxe.Serializer ) {
> s.serialize(a);
> s.serialize(b);
> s.serialize(c);
> s.serialize(d);
> }
> function hxUnserialize( s : haxe.Unserializer ) {
> a = s.unserialize();
> b = s.unserialize();
> c = s.unserialize();
> d = s.unserialize();
> }
> }

I think the issue is not serialization but the way you have originally
stored your data. If your data is UTF8 then StringTools.urlEncode("é")
will give you "%C3%A9" (two bytes). If OTOH the String is ASCII you will
get "%E9" (single byte > 128).

Hope that helps,

Nicolas

Message has been deleted

Jesus Boadas

unread,
Jan 22, 2014, 10:46:01 AM1/22/14
to haxe...@googlegroups.com
Sorry I mess myself with google groups

mmm

Well my data is stored in mysql with 
the database
character set: utf8 -- UTF-8 Unicode
collation: utf8_general_ci

the table
character set: utf8 -- UTF-8 Unicode
collation: utf8_general_ci

the varchar columns:
character set: utf8
collation: utf8_general_ci

I create a new database/table from scratch
php is using utf-8
apache is using utf-8
the html is in utf-8

Im trying to get a field with this value

abcébca

In the response I get
abc%E9bcannnnnnnngh

then the decoder complains because is trying to decode utf-8 but the special character is encoded with ascii

Where is the encoder getting the information of the character set of the string ?

I think I could get ride of this, declaring the table as ascii but all these characters gonna be replaced with the "?" symbol

Thanks

Jesus Boadas

unread,
Jan 22, 2014, 12:09:30 PM1/22/14
to haxe...@googlegroups.com
Ok I got to the root of the problem, Is a little offtopic but will post here so any other user can solve this puzzle.

By default mysql doesn't have utf-8 enabled 
Im using navicat and the software tell me that everything is using utf-8 but is not.

as you can see with this queries, I have a soup of character sets and collations

mysql> SHOW VARIABLES LIKE 'collation%';
+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | utf8_general_ci   |
| collation_database   | utf8_spanish_ci   |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set

mysql> SHOW VARIABLES LIKE 'character_set%';
+--------------------------+-----------------------------------------------+
| Variable_name            | Value                                         |
+--------------------------+-----------------------------------------------+
| character_set_client     | utf8                                          |
| character_set_connection | utf8                                          |
| character_set_database   | utf8                                          |
| character_set_filesystem | binary                                        |
| character_set_results    | utf8                                          |
| character_set_server     | latin1                                        |
| character_set_system     | utf8                                          |
| character_sets_dir       | c:\wamp\bin\mysql\mysql5.6.12\share\charsets\ |
+--------------------------+-----------------------------------------------+
8 rows in set

Now you need to tell the server to use utf-8, edit my.cnf om linux like systems or my.ini on windows and add the following

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
init-connect='SET NAMES utf8'

[client]
default-character-set=utf8

now restart mysql and verify

mysql> SHOW VARIABLES LIKE 'collation%';
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+----------------------+-----------------+
3 rows in set

mysql> SHOW VARIABLES LIKE 'character_set%';
+--------------------------+-----------------------------------------------+
| Variable_name            | Value                                         |
+--------------------------+-----------------------------------------------+
| character_set_client     | utf8                                          |
| character_set_connection | utf8                                          |
| character_set_database   | utf8                                          |
| character_set_filesystem | binary                                        |
| character_set_results    | utf8                                          |
| character_set_server     | utf8                                          |
| character_set_system     | utf8                                          |
| character_sets_dir       | c:\wamp\bin\mysql\mysql5.6.12\share\charsets\ |
+--------------------------+-----------------------------------------------+
8 rows in set


now our server is using utf-8 and urlencode/urldecode from the serializer is working fine.

Thanks Nicolas

flashline

unread,
Jan 26, 2014, 2:02:30 PM1/26/14
to haxe...@googlegroups.com
I had the same problem ! Thanks Jesus to put me on track. 
As I can't  to access to system files, I wrote in haxe 

cnx.request("SET character_set_client = utf8");
cnx
.request("SET character_set_results = utf8");
//etc

it works fine too.
jm
Reply all
Reply to author
Forward
0 new messages