kessler / node-regedit

Read, Write, List and do all sorts of funky stuff to the windows registry using node.js and windows script host
MIT License
277 stars 45 forks source link

regedit.list() throws SyntaxError when data includes tab (s) #12

Closed mh61503891 closed 8 years ago

mh61503891 commented 8 years ago

For example, "Adobe Acrobat Reader DC - Japanese" writes following entry to registry when installing:

This entry has a data including new lines and tabs, and the regedit.list() throws SyntaxError when reading above entry as follow:

Uncaught SyntaxError: Unexpected token
at Object.parse (native)
at DestroyableTransform.module.exports.vbsOutputTransform [as _transform] (Z:\hakuto\hakuto-client\node_modules\regedit\lib\helper.js:51:18)
at DestroyableTransform.Transform._read (Z:\hakuto\hakuto-client\node_modules\regedit\node_modules\through2\node_modules\readable-stream\lib\_stre
_transform.js:184:10)
at DestroyableTransform.Transform._write (Z:\hakuto\hakuto-client\node_modules\regedit\node_modules\through2\node_modules\readable-stream\lib\_str
m_transform.js:172:12)
at doWrite (Z:\hakuto\hakuto-client\node_modules\regedit\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:237:10)
at writeOrBuffer (Z:\hakuto\hakuto-client\node_modules\regedit\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:227:5)
at DestroyableTransform.Writable.write (Z:\hakuto\hakuto-client\node_modules\regedit\node_modules\through2\node_modules\readable-stream\lib\_strea
writable.js:194:11)
at StreamSlicer.ondata (_stream_readable.js:528:20)
at readableAddChunk (_stream_readable.js:146:16)
at StreamSlicer.Readable.push (_stream_readable.js:110:10)
at StreamSlicer.Transform.push (_stream_transform.js:128:32)
at StreamSlicer._separatorFlush (Z:\hakuto\hakuto-client\node_modules\regedit\node_modules\stream-slicer\index.js:63:7)
at StreamSlicer._transform (Z:\hakuto\hakuto-client\node_modules\regedit\node_modules\stream-slicer\index.js:33:8)
at StreamSlicer.Transform._read (_stream_transform.js:167:10)
at StreamSlicer.Transform._write (_stream_transform.js:155:12)
at doWrite (_stream_writable.js:292:12)
at writeOrBuffer (_stream_writable.js:278:5)
at StreamSlicer.Writable.write (_stream_writable.js:207:11)
at Socket.ondata (_stream_readable.js:528:20)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
at Pipe.onread (net.js:523:20)

Probably, this SyntaxError occurred if data includes tab (s). To check this, I have inputed a tab into other entry by regedit.exe then regedit.list() throws same error.

mh61503891 commented 8 years ago

https://github.com/ironSource/node-regedit/blob/45514bed635114891589abc2c554458417c3b8fc/lib/helper.js#L51

this.push(JSON.parse(chunk))

When chunk including \t, the \t must be escaped with \ according to RFC4627 JSON https://www.ietf.org/rfc/rfc4627.txt, page 4.

Check:

coffee> JSON.parse('["\\t"]')
[ '\t' ]
coffee> JSON.parse('["\t"]')
SyntaxError: Unexpected token   
  at Object.parse (native)
[...]
mh61503891 commented 8 years ago

https://github.com/ironSource/node-regedit/blob/45514bed635114891589abc2c554458417c3b8fc/vbs/util.vbs#L117

Additional replacement processes to escape extended characters (e.g., tab, backspace, etc.) are needed in Function JsonSafe.

The replacement rule are written in RFC 4627 Section "2.5. Strings" https://www.ietf.org/rfc/rfc4627.txt, page 4.

kessler commented 8 years ago

Hi @mh61503891

Would you be so kind as to post a small code snippet that replicates this problem so we can work on it?

Thanks

Yaniv

kessler commented 8 years ago

@mh61503891 bump

kessler commented 8 years ago

No response from submitting party, closing this issue for now