Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data strings changes over socket #3126

Closed
1 of 2 tasks
yotamgever opened this issue Nov 30, 2017 · 6 comments
Closed
1 of 2 tasks

data strings changes over socket #3126

yotamgever opened this issue Nov 30, 2017 · 6 comments
Milestone

Comments

@yotamgever
Copy link

Note: for support questions, please use one of these channels: stackoverflow or slack

You want to:

  • report a bug
  • request a feature

Current behaviour

when emitting an object as data and within it using a string of (or the unicode \u2265) it turns it to the string letter e and trurns to d

Steps to reproduce (if the current behaviour is a bug)

client side

channel.emit('data', {data:'≥'});

server side

socket.on('data',({data:bla})=>{
console.log(bla); // prints 'e'
});

Note: the best way to get a quick answer is to provide a failing test case, by forking the following fiddle for example.

Expected behaviour

that the data will stay the same consistently

Setup

  • OS: Windows
  • browser: Chrome 62
  • socket.io version: 1.7.2

Other information (e.g. stacktraces, related issues, suggestions how to fix)

@deanshub
Copy link

deanshub commented Dec 4, 2017

This happens only when the socket hasn't upgraded (first use) over xhr,
after it upgrades to websocket all data is sent correctly

@deanshub
Copy link

deanshub commented Dec 4, 2017

see #451 and #572

@darrachequesne
Copy link
Member

There was an issue regarding utf8 parsing in version 1.x, could you please try with version 2.x ?

Related:

@deanshub
Copy link

deanshub commented Dec 6, 2017

tried it with 2.0.4, still happens...
fixed it with encoding and decoding the data with this code:
client side

function strencode( data ) {
	return encodeURIComponent( escape( JSON.stringify( data ) ) );
}

server side

function strdecode( data ) {
	return JSON.parse( unescape( decodeURIComponent( data ) ) );
}

@yotamgever
Copy link
Author

Yeah that's seems to be working. Thanks!

@darrachequesne
Copy link
Member

For future readers: I think that's because the version of the client and the server did not match (v1 and v2 were indeed incompatible).

@darrachequesne darrachequesne added this to the 2.0.0 milestone Feb 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants