shimaore / esl

Node.js client and server for FreeSwitch Event Socket
The Unlicense
123 stars 41 forks source link

Crash on not latin charasters in Event #27

Closed gendalf closed 8 years ago

gendalf commented 8 years ago

When set caller name in utf-8, event receipt in ascii and crush on JSON.parse

Need to read socket in utf8 encoding

shimaore commented 8 years ago

@gendalf do you set the caller-name using Node.js or some other method (e.g. XML dialplan)? Just trying to reproduce the issue. (When sending UTF-8 in event headers from Node.js, I get %-encoded responses, which produces garbage once they go through the module, but doesn't crash the parser.)

Also I'm going to have to make sure that using .setEncoding('utf8') on the socket doesn't change things in unexpected ways, I'll feel more comfortable after I write a few tests to get a better handle on this. :)

gendalf commented 8 years ago

I am set caller name in nodejs

call.api "uuid_setvar_multi #{uuid} person_id='#{person_id}';ringback='%(2000,4000,440.0,480.0)';instant_ringback=true;ignore_early_media=true;effective_caller_id_name='#{person_name}'"

person_name = "Толя Кротик" // cyrillic

When getting event in ascii (by default), body have json with ".... "variable_caller_id_name":"PP2P0QP5P=P: P>P.QP8P9P!P5QP3P5P5P2P8QP"P>P;Q PQP>QP8P:",... 'P"P>' - ops... error

when setEncoding('utf8') - all fine inside message, but FS send Content-Length in bytes, not in utf8 chars... so body parsing wrong when try get body with substring...

shimaore commented 8 years ago

Thank you for the great report @gendalf ! Please test v4.1.0 and let me know if things are better!

gendalf commented 8 years ago

Now it works fine! Great job @shimaore !