ufo icon indicating copy to clipboard operation
ufo copied to clipboard

Only apply trailing slash utilities to supported protocols

Open pi0 opened this issue 2 years ago • 3 comments

Extracted from #175

Utilities for trailing slash (withTrailingSlash) operate on URIs that have a meaning for trailing slash. http, https, (perhaps rsync, ftp and custom protocols are included)

However there are protocols like data:, mailto:, blob:, etc do not expect a trailing slash to be added or removed from the end.

Having a check (for invalid or invalid list of protocols) is costly on runtime and also not maintainable. One solution would be to support new options to both opt-in and also configure the list which is against costly.

I am mainly thinking of differentiating based on proto: and proto:/ proto:// to do this automatically. (it still needs a new option to opt out btw)

pi0 avatar Nov 15 '23 16:11 pi0

Hello,

We discussed protocols before in #70. Summary there is a list of known protocols https://en.m.wikipedia.org/wiki/List_of_URI_schemes and an IANA list here https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml

Probably I could take care of it next week, hopefully but before would like to make tests with %100 coverage 😄

Thanks!

divine avatar Nov 15 '23 20:11 divine

Thanks for the links dear @divine. I am thinking of a strategy that does not requires a maintainable list btw as we need to keep ufo compact. But finally if no other ways, behind a flag we might use a compiled regex.

pi0 avatar Nov 15 '23 21:11 pi0

I am mainly thinking of differentiating based on proto: and proto:/ proto:// to do this automatically. (it still needs a new option to opt out btw)

Might break for some, e.g.:

  • aaa:// -> no trailing slash ever
  • facetime:// -> no trailing slash ever
  • cvs:// -> no trailing slash after ; (if ; is set)
  • dict:// -> no trailing slash at the end ever
  • gizmoproject:// -> no trailing slash ever

TheAlexLichter avatar Nov 15 '23 23:11 TheAlexLichter