When using sparql_query to query the Wikidata SPARQL endpoint with string literals containing accented characters (e.g. "Nestlé"@en), the query returns 0 results even though the entity exists with that exact label.
Root cause
The é character (U+00E9, UTF-8: C3 A9) appears to be corrupted or incorrectly encoded when the tool serializes the SPARQL query string into the HTTP request body. Wikidata confirms the label is stored as precomposed é (U+00E9).
Steps to reproduce
Run the following query against https://query.wikidata.org/sparql:
```sparql
SELECT ?item WHERE {
?item rdfs:label "Nestlé"@en .
}
LIMIT 5
```
Returns 0 results. The entity Q160746 has English label "Nestlé" and should match.
Workaround
Use wikibase:mwapi EntitySearch service instead of rdfs:label exact match:
```sparql
SELECT ?item ?itemLabel WHERE {
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:endpoint "www.wikidata.org" ;
wikibase:api "EntitySearch" ;
wikibase:limit "5" ;
mwapi:search "Nestle" ;
mwapi:language "fr" .
?item wikibase:apiOutputItem mwapi:item .
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
```
Note: this only works for Wikidata and requires omitting the accent in the search term, which is a poor workaround.
Expected behavior
UTF-8 string literals in SPARQL queries should be transmitted as-is, without normalization or corruption of non-ASCII characters.
When using
sparql_queryto query the Wikidata SPARQL endpoint with string literals containing accented characters (e.g."Nestlé"@en), the query returns 0 results even though the entity exists with that exact label.Root cause
The
écharacter (U+00E9, UTF-8:C3 A9) appears to be corrupted or incorrectly encoded when the tool serializes the SPARQL query string into the HTTP request body. Wikidata confirms the label is stored as precomposedé(U+00E9).Steps to reproduce
Run the following query against
https://query.wikidata.org/sparql:```sparql
SELECT ?item WHERE {
?item rdfs:label "Nestlé"@en .
}
LIMIT 5
```
Returns 0 results. The entity Q160746 has English label "Nestlé" and should match.
Workaround
Use
wikibase:mwapiEntitySearch service instead ofrdfs:labelexact match:```sparql
SELECT ?item ?itemLabel WHERE {
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:endpoint "www.wikidata.org" ;
wikibase:api "EntitySearch" ;
wikibase:limit "5" ;
mwapi:search "Nestle" ;
mwapi:language "fr" .
?item wikibase:apiOutputItem mwapi:item .
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
```
Note: this only works for Wikidata and requires omitting the accent in the search term, which is a poor workaround.
Expected behavior
UTF-8 string literals in SPARQL queries should be transmitted as-is, without normalization or corruption of non-ASCII characters.