Escape Characters in links

0 votes
asked Aug 11, 2020 in Question / help by Kidau (120 points)

Hello,

In hyperlinks, round brackets { } are used for optional tooltips. 

I want to used links to point to API documentation and URLs are like that (for instance): /get-/customers/{customerId}

Is it possible to escape round brackets in order to have conditionnal parameters and not tooltip ?

Thanks

commented Aug 12, 2020 by Martin

I'm no expert, I just took interest and did a bit of googling.  But it looks like braces (or curly brackets (don't call them round brackets!), see https://en.wikipedia.org/wiki/Bracket#Names_for_various_bracket_symbols) are bad practice in URIs as they are part of the definition of unsafe characters (see https://tools.ietf.org/html/rfc1738 page 3).  They crop up because they are valid characters in URI templates (but not URIs themselves).  I found a few examples of people tripping over this in relation to API documentation: https://meta.stackexchange.com/questions/79057/curly-brackets-in-urlshttps://github.com/Swagger2Markup/swagger2markup/issues/10https://github.com/ruby-grape/grape-swagger/issues/197.

Notably I leafed through some API documentation for Stackexchange and Facebook, and they don't use curly brackets in the api doc urls.

That said, the correct way to include unsafe characters in a url is to encode them.  So { would be replaced with %7B and } would be replaced with %7D.

I couldn't find a public example url using curly brackets, but here is [a neatly relevant] example that includes an unsafe "^" character, with it also encoded as %5E:

http://www.plantuml.com/plantuml/png/hSwnIWGn483XtgUOnd8kbSqLSWg-WTrn1zdic8IRP9RCP8E8FhjvYAr_-FakQhvPB_pqnZaGu2kyom9di4JG6yFrcimsFJitnZYPvwp5rvEqwFweyKDgZgva3OvxzKOXtKVoXhHJ-yP1oqexbgw6Zoe3_IBTS8wHQf0rr-X-FaNOyWPVqg2Gge_q2rrdW_ljTXpi-UNZGDgyJTo5wjeB_mC0

http://www.plantuml.com/plantuml/umla/hSwnIWGn483XtgUOnd8kbSqLSWg-WTrn1zdic8IRP9RCP8E8FhjvYAr_-FakQhvPB_pqnZaGu2kyom9di4JG6yFrcimsFJitnZYPvwp5rvEqwFweyKDgZgva3OvxzKOXtKVoXhHJ-yP1oqexbgw6Zoe3_IBTS8wHQf0rr-X-FaNOyWPVqg2Gge_q2rrdW_ljTXpi-UNZGDgyJTo5wjeB_mC0

@startuml
Alice -> Bob : the url [[https://www.talisman.org/~erlkonig/misc/lunatech^what-every-webdev-must-know-about-url-encoding/{Tooltip for message} using ^]]
Alice -> Bob : the url [[https://www.talisman.org/~erlkonig/misc/lunatech%5Ewhat-every-webdev-must-know-about-url-encoding/{Tooltip for message} using %5E]]
@enduml

TL;DR; Hopefully encoding { & } as %7B & %7D works for your use case.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

[Antispam2 Feature: please please wait 1 or 2 minutes (this message will disappear) before pressing the button otherwise it will fail](--------)
To avoid this verification in future, please log in or register.
...