Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orion returns illegal JSON in some situations #3280

Closed
fgalan opened this issue Aug 31, 2018 · 2 comments
Closed

Orion returns illegal JSON in some situations #3280

fgalan opened this issue Aug 31, 2018 · 2 comments
Assignees
Labels
Milestone

Comments

@fgalan
Copy link
Member

fgalan commented Aug 31, 2018

Creating this entity (note the \n):

$ curl localhost:1026/v2/entities -s -S -H 'Content-Type: application/json' -d @- <<EOF
{
  "id": "E",
  "type": "T",
  "A": {
    "value": "000FF\nABCDGC",
    "type": "Text"
  }
}
EOF

Stored at DB as:

{
	"_id" : {
		"id" : "E",
		"type" : "T",
		"servicePath" : "/"
	},
	"attrNames" : [
		"A"
	],
	"attrs" : {
		"A" : {
			"type" : "Text",
			"creDate" : 1535718069,
			"modDate" : 1535718069,
			"value" : "000FF\nABCDGC",
			"mdNames" : [ ]
		}
	},
	"creDate" : 1535718069,
	"modDate" : 1535718069,
	"lastCorrelator" : "57df79d6-ad18-11e8-9744-000c29173617"
}

You can retrieve it this way:

$ curl -s -S localhost:1026/v2/entities/E
{"id":"E","type":"T","A":{"type":"Text","value":"foo","metadata":{}},"A":{"type":"Text","value":"000FF
ABCDGC","metadata":{}}}

But note that is is illegal JSON.

$ curl -s -S localhost:1026/v2/entities/E | python -mjson.tool
Invalid control character at: line 1 column 103 (char 102)

Orion must not return never illegal JSON. The problem seems to be located in the rendering stage.

@fgalan
Copy link
Member Author

fgalan commented Aug 31, 2018

Similar test, using a subscription:

$ curl -v localhost:1026/v2/subscriptions -s -S -H 'Content-Type: application/json' -d @- <<EOF
{
  "description": "A subscription\nwith a newline",
  "subject": {
    "entities": [
      {
        "id": "Room1",
        "type": "Room"
      }
    ]
  },
  "notification": {
    "http": {
      "url": "http://localhost:1028/accumulate"
    }
  }
}
EOF

In DB is:

{
	"_id" : ObjectId("5b8935d9e286793b32236883"),
	"expiration" : NumberLong("9223372036854775807"),
	"reference" : "http://localhost:1028/accumulate",
	"custom" : false,
	"throttling" : NumberLong(0),
	"servicePath" : "/#",
	"description" : "A subscription\nwith a newline",
	"status" : "active",
	"entities" : [
		{
			"id" : "Room1",
			"isPattern" : "false",
			"type" : "Room",
			"isTypePattern" : false
		}
	],
	"attrs" : [ ],
	"metadata" : [ ],
	"blacklist" : false,
	"conditions" : [ ],
	"expression" : {
		"q" : "",
		"mq" : "",
		"geometry" : "",
		"coords" : "",
		"georel" : ""
	},
	"format" : "normalized"
}

Rendered as legal JSON:

$ curl -s -S localhost:1026/v2/subscriptions/5b8935d9e286793b32236883 | python -mjson.tool
{
    "description": "A subscription\nwith a newline",
    "id": "5b8935d9e286793b32236883",
    "notification": {
        "attrs": [],
        "attrsFormat": "normalized",
        "http": {
            "url": "http://localhost:1028/accumulate"
        }
    },
    "status": "active",
    "subject": {
        "condition": {
            "attrs": []
        },
        "entities": [
            {
                "id": "Room1",
                "type": "Room"
            }
        ]
    }
}

This is due to subscriptions and entities are using different rendering logic. This remarks the importance of having only one way of rendering JSON along the code, so bugfixing can be done in just one place. This stresses the need of unification and simplification already described in #1298

@fgalan
Copy link
Member Author

fgalan commented Sep 12, 2018

Fixed by PR #3285, .test and CNR added in PR #3291

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

No branches or pull requests

1 participant