Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

console.log: wrong output when using '\' in Object keys #6835

Closed
avetisk opened this issue Jan 9, 2014 · 2 comments
Closed

console.log: wrong output when using '\' in Object keys #6835

avetisk opened this issue Jan 9, 2014 · 2 comments

Comments

@avetisk
Copy link

avetisk commented Jan 9, 2014

Case 1

Adds an extra '' when key is ending with 2+ ''.

var obj = {
  '\\': 1,
  '\\\\': 2,
  '\\\\\\': 3,
  '\\\\\\\\': 4,
};
console.log(obj);

Expected:

{ '\': 1, '\\': 2, '\\\': 3, '\\\\': 4 }

Got:

{ '\': 1, '\\\': 2, '\\\\\': 3, '\\\\\\\': 4 }

Case 2

Leaves '' as they are

var obj = {
  '\\sometext': 1,
  '\\\\sometext': 2,
  '\\\\\\sometext': 3,
  '\\\\\\\\sometext': 4,
};
console.log(obj);

Expected:

{ '\sometext': 1, '\\sometext': 2, '\\\sometext': 3, '\\\\sometext': 4 }

Got:

{ '\\sometext': 1, '\\\\sometext': 2, '\\\\\\sometext': 3, '\\\\\\\\sometext': 4 }

Case 3

Any following '' is not resolved any more.

var obj = {
  '\\': 1,
  '\\\\': 2,
  '\\\\\\': 3,
  '\\\\\\\\': 4,
};
console.log(obj, 'a\nb', '\\', '\\\\', '\\\\\\');

Expected:

{ '\': 1, '\\': 2, '\\\': 3, '\\\\': 4 } 'a
b' '\' '\\' '\\\'

Got:

{ '\': 1, '\\\': 2, '\\\\\': 3, '\\\\\\\': 4 } 'a\nb' '\\' '\\\\' '\\\\\\'

Nota Bene

It's really about console as this produces no error:

assert(Object.keys({'\\': 1, '\\\\': 2})[1].length === 2)

Info

  • node 0.10.22
  • tested both on OS X 10.9 and Ubuntu 13.04
@geggleto
Copy link

geggleto commented Jan 9, 2014

Nothing wrong here...
has to do with Console.Log....using Util.Inspect iirc.

var obj = {
  '\\': 1,
  '\\\\': 2,
  '\\\\\\': 3,
  '\\\\\\\\': 4,
};

if (obj['\\'] === 1)
{
    console.log("Found");
}

C:\node\issue6835>node -v
v0.10.20

C:\node\issue6835>node test.js
Found

@avetisk
Copy link
Author

avetisk commented Jan 9, 2014

@geggleto: it seems right:

22c68fd/lib/console.js#L52:

Console.prototype.log = function() {
  this._stdout.write(util.format.apply(this, arguments) + '\n');
};

So I guess the original bug is in util.format.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants