Closed fisuda closed 3 years ago
Try using double-quotes for the string (and URL-encode the quotes):
... ?q=name==%221234%22
NGSIv2 and NGSI-LD differs a little here. See chapter 4.9 in the NGSI-LD API spec:
...
ComparableValue = Number / quotedStr / dateTime / date / time
...
quotedStr = String ; "*char"
...
String shall be a text string as mandated by the JSON Specification, following the ABNF Grammar,
production rule named String, section 7 of IETF RFC 8259 [6].
Spaces are a bit tricky, Hopefully it works both with and without URL-encoding the spaces ...
Let me know how it goes.
Thank you for your advice. I tried it. It works.
curl -s 'http://orion-ld:1026/ngsi-ld/v1/entities?q=name==%221234%22' \
-H 'Link: <https://context.lab.letsfiware.jp/test-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' | jq .
[
{
"@context": "https://context.lab.letsfiware.jp/test-context.jsonld",
"id": "urn:ngsi-ld:sensor001",
"type": "Sensor",
"name": {
"type": "Property",
"value": "1234"
},
"temperature": {
"type": "Property",
"value": 25
}
}
]
I have a further question. When an attribute name is multibyte characters, how should I specify a query? The case is as follows.
short name
"name": {
"type": "Property",
"value": "1234"
},
IRI
"https://context.lab.letsfiware.jp/dataset#name": {
"type": "Property",
"value": "1234"
},
In the case of q=name==%221234%22
{
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
"title": "ngsi-ld query language: invalid character",
"detail": "�"
}
In the case of q=https%3A%2F%2Fcontext.lab.letsfiware.jp%2Fdataset%23%82%8E%82%81%82%8D%82%85==%221234%22
{
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
"title": "ngsi-ld query language: invalid character",
"detail": "/"
}
q=%22name%22==%221234%22
{
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
"title": "ngsi-ld query language: invalid start token",
"detail": "StringValue"
}
The following is a test script.
#!/bin/sh
curl -s http://orion-ld:1026/version
curl -s -iX POST http://orion-ld:1026/ngsi-ld/v1/entityOperations/upsert -H "Content-Type: application/json" \
-H 'Link: <https://context.lab.letsfiware.jp/test-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
--data '[
{
"id": "urn:ngsi-ld:sensor001",
"type": "Sensor",
"name": {
"type": "Property",
"value": "1234"
},
"temperature": {
"type": "Property",
"value": 25
}
},
{
"id": "urn:ngsi-ld:sensor002",
"type": "Sensor",
"name": {
"type": "Property",
"value": "5678"
},
"temperature": {
"type": "Property",
"value": 30
}
}
]'
curl -s 'http://orion-ld:1026/ngsi-ld/v1/entities?q=name==%221234%22' \
-H 'Link: <https://context.lab.letsfiware.jp/test-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' | jq .
{
"orionld version": "post-v0.6",
"orion version": "1.15.0-next",
"uptime": "0 d, 0 h, 15 m, 31 s",
"git_hash": "nogitversion",
"compile_time": "Sun Feb 28 10:19:18 UTC 2021",
"compiled_by": "root",
"compiled_in": "buildkitsandbox",
"release_date": "Sun Feb 28 10:19:18 UTC 2021",
"doc": "https://fiware-orion.readthedocs.org/en/master/"
}
HTTP/1.1 204 No Content
Connection: Keep-Alive
Date: Mon, 01 Mar 2021 11:58:14 GMT
{
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
"title": "ngsi-ld query language: invalid character",
"detail": "�"
}
When an attribute name is multibyte characters ...
Frankly, I have never tried that. The first thing I would do would be to URL-encode the name (that goes as a URI parameter). And I mean, just try to url-encode name- don't add any quotes - that's only for string values (on Right-Hand Side).
So, I tried - took me quite some time to figure out how to make curl
accept the URL parameter with "funny characters" in it ...
It doesn't work - I will need to "broaden" the set of characters I accept for variable names in 'q'.
This is what I send:
curl localhost:9999/ngsi-ld/v1/entities?prettyPrint=yes -X GET --data-urlencode "q=name==1" -G -H "Accept: application/json"
And this is what I get:
{
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
"title": "ngsi-ld query language: invalid character",
"detail": "ï"
}
At least, I'm able to reproduce the problem and I can start to try and find a fix! :)
I removed the check for forbidden characters in variable names of the 'q' string - seems to be working now. I'll have to consult with my colleagues and boss before I merge this.
I decided to merge the PR. Please try it and let me know
I tried it. The results were as expected. Thank you for your help!
#!/bin/sh
curl -s http://orion-ld:1026/version
echo
curl -s -iX POST http://orion-ld:1026/ngsi-ld/v1/entityOperations/upsert -H "Content-Type: application/json" \
-H 'Link: <https://context.lab.letsfiware.jp/test-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
--data '[
{
"id": "urn:ngsi-ld:sensor001",
"type": "Sensor",
"name": {
"type": "Property",
"value": "1234"
},
"temperature": {
"type": "Property",
"value": 25
}
},
{
"id": "urn:ngsi-ld:sensor002",
"type": "Sensor",
"name": {
"type": "Property",
"value": 1
},
"temperature": {
"type": "Property",
"value": 30
}
}
]'
curl -s 'http://orion-ld:1026/ngsi-ld/v1/entities?prettyPrint=yes' -X GET --data-urlencode "q=name==\"1234\"" -G \
-H 'Link: <https://context.lab.letsfiware.jp/test-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"'
echo
curl -s 'http://orion-ld:1026/ngsi-ld/v1/entities?prettyPrint=yes' -X GET --data-urlencode "q=name==1" -G \
-H 'Link: <https://context.lab.letsfiware.jp/test-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"'
{
"orionld version": "post-v0.6",
"orion version": "1.15.0-next",
"uptime": "0 d, 0 h, 43 m, 18 s",
"git_hash": "nogitversion",
"compile_time": "Mon Mar 1 17:36:28 UTC 2021",
"compiled_by": "root",
"compiled_in": "buildkitsandbox",
"release_date": "Mon Mar 1 17:36:28 UTC 2021",
"doc": "https://fiware-orion.readthedocs.org/en/master/"
}
HTTP/1.1 204 No Content
Connection: Keep-Alive
Date: Mon, 01 Mar 2021 21:18:37 GMT
[
{
"@context": "https://context.lab.letsfiware.jp/test-context.jsonld",
"id": "urn:ngsi-ld:sensor001",
"type": "Sensor",
"name": {
"type": "Property",
"value": "1234"
},
"temperature": {
"type": "Property",
"value": 25
}
}
]
[
{
"@context": "https://context.lab.letsfiware.jp/test-context.jsonld",
"id": "urn:ngsi-ld:sensor002",
"type": "Sensor",
"name": {
"type": "Property",
"value": 1
},
"temperature": {
"type": "Property",
"value": 30
}
}
]
$ docker images | grep orion-ld
fiware/orion-ld 0.7-PRE-74 49fb0b1b6858 4 hours ago 978MB
The
invalid character
error occurs when specifying multibyte characters to a query condition inGET /ngsi-ld/v1/entities
. The following is a script to reproduce this issue. A string that has multibyte characters is1234
.The following is a result run it.
The following is a script for Orion 2.5.2.
Orion has found an entity that matched the query condition.