Skip to content

sparql_query: accented characters in string literals are corrupted before HTTP transmission #22

Description

@aborruso

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions