michaelwittig / node-q

Q interfacing with Node.js
MIT License
52 stars 14 forks source link

charCode 32 (" ") deserialized into null #13

Closed thekvn closed 8 years ago

thekvn commented 8 years ago

We are having issues with string based responses from q, spaces are being translated into nulls

Test app

#!/usr/bin/env node

var cmd = process.argv[2] || '';
var nodeq = require('node-q');
var assert = require('assert');

nodeq.connect({
  host: 'localhost',
  port: 5080
}, function(err, q) {
  q.k(cmd, function(err, out) {
    console.log("in:", cmd, "out:", out);
    process.exit(0);
  });
});

output

❯ ./test.js '"this is a string"'
in: "this is a string" out: thisnullisnullanullstring

We expected " " to translate into " " in javascript.

Code that deserializes ' ' into null https://github.com/michaelwittig/node-q/blob/master/lib/c.js#L53-L60

Tested for here: https://github.com/michaelwittig/node-q/blob/master/itest/deserialization.js#L296-L303

Is this behaviour intended?

Thanks

michaelwittig commented 8 years ago

Hi Kevin,

a) null " "
1b

that's why it turns into null in JavaScript. According to http://code.kx.com/wiki/Reference/Datatypes char 32 is null. The thing I could imagine i introducing a config parameter to turn this off. Is that fine?

thekvn commented 8 years ago

Ah I see.

Yes a config option to change this behaviour passed into node-q#connect would be great.

michaelwittig commented 8 years ago

included in release v1.0.1.

nodeq.connect({
  host: 'localhost',
  port: 5080,
  emptyChar2null: false
}, function(err, q) {
  q.k(cmd, function(err, out) {
    console.log("in:", cmd, "out:", out);
    process.exit(0);
  });
});