[SERVER-6732] V8 Scripting: Multiline JSON Arrays break using square brackets alone Created: 08/Aug/12  Updated: 15/Aug/12  Resolved: 08/Aug/12

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.0.2
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Dan Dart Assignee: Tad Marshall
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OSX


Issue Links:
Duplicate
duplicates SERVER-6693 Copy-pasting multi-line strings with ... Closed
Operating System: ALL
Participants:

 Description   

Whereas usually you can start typing an object, e.g.:

> object = {
... "a": "b",
... "c": "d"
... };
{ "a" : "b", "c" : "d" }
>

the same breaks when you try to do so with an array - with the square bracket on its own.

> array = [
Wed Aug  8 15:15:08 SyntaxError: syntax error (shell):1

It works when there's something after the square bracket, e,g.:

> array = ["a",
... "b"]
[ "a", "b" ]

or:

> array = [{
... "a":"b",
... }]
[ { "a" : "b" } ]

And fails when the remainder is concluded without the square bracket on the same line:

> array = [{
... "a":"b"
... }
Wed Aug  8 15:17:40 SyntaxError: missing ] after element list (shell):3

This only happens on the top level, as demonstrated using a nested array:

> array = [{
... "a":[
... "a"
... ]
... }]
[ { "a" : [ "a" ] } ]

I think this is to do with the V8 engine but don't really know.



 Comments   
Comment by Dan Dart [ 08/Aug/12 ]

Thanks for the clear-up.

Comment by Tad Marshall [ 08/Aug/12 ]

Thanks for the report.

Yes, the code for entering and staying in multi-line mode wasn't checking for square braces the way it does for parentheses and wavy braces. This was just fixed for 2.2.0-rc1 in SERVER-6693.

Your third case,

array = ["a",

works because of the dangling comma.

The bug is not related to V8. The multi-line mode is something that the shell does before it passes JavaScript to the JavaScript engine (SpiderMonkey or V8, depending on which build you run).

Comment by Dan Dart [ 08/Aug/12 ]

Jira appears to have fiddled line endings...

Generated at Thu Feb 08 03:12:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.