Page MenuHomePhabricator

Escape parentheses in WDQS URL
Closed, ResolvedPublic

Description

It would be useful if WDQS URL-escaped parentheses (()) in the address it builds from the query (https://query.wikidata.org/#QUERY_GOES_HERE). For example, Twitter sometimes thinks that the parentheses are not part of the link, and so you have to escape them manually (Workaround: xclip -o | sed 's/(/%28/g;s/)/%29/g' | xclip).

This is similar to T40265, in that it could be considered a bug in another application (here, Twitter), but as WDQS URLs are already not really readable (nor, I think, intended to be), I hope you’ll still consider mitigating it on the WDQS end.

To clarify: entering and running the query

SELECT (COUNT(?human) AS ?count)
WHERE { ?human wdt:P31 wd:Q5. }

should result in the URL

https://query.wikidata.org/#SELECT%20%28COUNT%28%3Fhuman%29%20AS%20%3Fcount%29%0AWHERE%20%7B%20%3Fhuman%20wdt%3AP31%20wd%3AQ5.%20%7D

and not

https://query.wikidata.org/#SELECT%20(COUNT(%3Fhuman)%20AS%20%3Fcount)%0AWHERE%20%7B%20%3Fhuman%20wdt%3AP31%20wd%3AQ5.%20%7D

.

Details

Related Changes in Gerrit:

Event Timeline

Restricted Application added subscribers: Zppix, Aklapper. · View Herald Transcript
Smalyshev subscribed.

I would recommend using URL shortener if you really intend putting links into Twitter. Just click on the link image on the top right and use the short links - most query links in full form would be too long for Twitter.

I actually used to use the short bit.ly links, but stopped because

most query links in full form would be too long for Twitter.

is incorrect: Twitter has its own link shortener (t.co), which it forces on you, and so every link counts as exactly 23 characters, regardless of its actual length. It’s pointless to use an external URL shortener on Twitter; all it does is unnecessarily hide the link content.

(Example: the full link in this tweet is 2354 characters long, but because only the short t.co URL counts, it still fits in one tweet.

This should be a pretty easy change see this line

Feel free to submit a patch then I will merge it.

That’s odd, because occasionally curly braces also cause problems, and according to MDN encodeURIComponent always escapes those. I guess that perhaps the browser gets confused when it partially decodes the URL to display it in the location bar…

Change 292399 had a related patch set uploaded (by Lucas Werkmeister):
URL-encode additional characters

https://gerrit.wikimedia.org/r/292399

Change 292399 merged by jenkins-bot:
URL-encode additional characters

https://gerrit.wikimedia.org/r/292399