Skip to content

Commit

Permalink
Fix encoding issues, re #13
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Jan 22, 2014
1 parent 6b364ca commit ce02b09
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions index.js
Expand Up @@ -152,13 +152,11 @@ exports.request = function (options, callback) {
if (!options.encoding && options.encoding !== null) {
options.encoding = 'utf8';
}
if (options.encoding) {
encoding = options.encoding;
if (encoding === 'ascii') {
options['use-ascii'] = true;
}
delete options.encoding;
encoding = options.encoding;
if (encoding === 'ascii') {
options['use-ascii'] = true;
}
delete options.encoding;

//Parse POST data
if (options.data && typeof options.data === 'object') {
Expand Down Expand Up @@ -388,7 +386,7 @@ exports.copy = function (obj) {
var copy = {};
for (var i in obj) {
if (typeof obj[i] === 'object') {
copy[i] = exports.copy(obj[i]);
copy[i] = copy[i] ? exports.copy(obj[i]) : null;

This comment has been minimized.

Copy link
@panurgy

panurgy Jan 22, 2014

Silly question - it seems that this will take every property that is assigned a falsy value and mis-assign it to null instead.

Thus, an object like this:

{
   foo: 0,
   bar: false
}

Will become this:

{
   foo: null,
   bar: null
}

Or do I need more caffeine .... ?

This comment has been minimized.

Copy link
@chriso

chriso Jan 22, 2014

Author Contributor

The only falsey value that also passes typeof obj[i] === 'object' is null

This comment has been minimized.

Copy link
@chriso

chriso Jan 22, 2014

Author Contributor
~ $ node
> typeof 0
'number'
> typeof false
'boolean'
> typeof undefined
'undefined'
> typeof 'foo'
'string'
> typeof [1,2,3]
'object'
> [] ? 'true' : 'false'
'true'
> {} ? 'true' : 'false'
'true'
> typeof /foo/
'object'
> /foo/ ? 'true' : 'false'
'true'

This comment has been minimized.

Copy link
@chriso

chriso Jan 22, 2014

Author Contributor

@panurgy actually, my bad, it should be obj[i] ? exports.copy(obj[i]) : null;. I'll push a 0.4.1 in a sec

} else {
copy[i] = obj[i];
}
Expand Down

0 comments on commit ce02b09

Please sign in to comment.