Node: JSON.stringify fails parsing session object

Created on 19 Jun 2017  路  8Comments  路  Source: nodejs/node

Version: v6.11.0
Platform: Linux eric-ThinkPad-X220 4.8.0-36-generic #36~16.04.1-Ubuntu SMP Sun Feb 5 09:39:57 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Subsystem:

  1. inside express-session, MemeoryStore
  2. session printed:
Session {
  cookie: 
   { path: '/',
     _expires: 2017-06-19T17:23:33.834Z,
     originalMaxAge: 60000,
     httpOnly: true },
  user: 
   { nickname: 'testuser1497892948433',
     username: 'testuser1497892948433',
     password: 'b4006d83bf607caaf68ea6d4625245cc',
     email: '[email protected]',
     url: null,
     location: null,
     signature: null,
     profile: null,
     weibo: null,
     avatar: 'https://www.gravatar.com/avatar/487023740ef2996262d47b405ca1b1f8?size=48',
     githubId: null,
     githubUsername: null,
     githubAccessToken: null,
     blocked: false,
     score: 0,
     threads: 0,
     replies: 0,
     followers: 0,
     followings: 0,
     starred: null,
     level: null,
     active: true,
     accessToken: '44bd014e746112b3e6ac8a4c43b78671',
     salt: '[object Promise]',
     id: 89,
     goodAt: null,
     favoriteTags: 0,
     favoriteThreads: 0,
     createdAt: '2017-06-19T17:22:33.000Z',
     updatedAt: '2017-06-19T17:22:33.000Z',
     mailingReplies: null,
     passwordRetrieveTime: null,
     passwordRetrieveKey: null } }
  1. JSON.stringify parsed:
{"cookie":{"originalMaxAge":60000,"expires":"2017-06-19T17:23:33.834Z","httpOnly":true,"path":"/"},"user":{"0":"u","1":"s","2":"e","3":"r"}}
question

Most helpful comment

more acceptable behaviors might be:

@calidion The behavior of JSON.stringify() is specified in https://www.ecma-international.org/ecma-262/5.1/#sec-15.12.3 and is not implemented by Node.js, but by the V8 engine upon which Node.js relies.

If you want to see the behavior of JSON.stringify() change in Node.js, you will have to first determine if you are asking for a change in the algorithm specification or if you believe you have found a bug in V8. If the former, you will need to take it up with TC-39 (the committee that determines the contents of the ECMAScript specification). If the latter, you will need to report in the issue tracker for the Google V8 project.

All 8 comments

I'm not sure I understand the question. The output in step 2 is not JSON. Node also doesn't control the JSON object. Can you check with the express-session and MemoryStore teams first?

I think there's something wrong with your user object. Would you give out some context?

This would be better asked on the nodejs/help issue tracker instead.

Closing this issue here as it does not appear to be a Node.js issue

it is true that the object is somewhat special.
but the problem is that it can be parsed in a wrong way and without any warning or exception.
regardless of what the object is,
JSON.stringify should not return JSON object as:

{"0":"u","1":"s","2":"e","3":"r"}

this result is surely wrong and non acceptable.

more acceptable behaviors might be:

  1. if the object can be acceptable, turn it to an object. then parse it properly and return a right result.
  2. if the object can not be acceptable, issue an exception and exit the program.

more acceptable behaviors might be:

@calidion The behavior of JSON.stringify() is specified in https://www.ecma-international.org/ecma-262/5.1/#sec-15.12.3 and is not implemented by Node.js, but by the V8 engine upon which Node.js relies.

If you want to see the behavior of JSON.stringify() change in Node.js, you will have to first determine if you are asking for a change in the algorithm specification or if you believe you have found a bug in V8. If the former, you will need to take it up with TC-39 (the committee that determines the contents of the ECMAScript specification). If the latter, you will need to report in the issue tracker for the Google V8 project.

@Trott

You are right.

But I think it is not my duty to report such inconsistency.
I'm using node.js not ecma or v8.

if you don't think that is a problem, just leave it alone.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vsemozhetbyt picture vsemozhetbyt  路  3Comments

loretoparisi picture loretoparisi  路  3Comments

jmichae3 picture jmichae3  路  3Comments

seishun picture seishun  路  3Comments

addaleax picture addaleax  路  3Comments