pkg: URI validation
Currently I need to hack together some regular expressions, which probably aren't necessarily 100% accurate see: https://github.com/slsa-framework/slsa/blob/0e1182e951f59ab5934bdb0906681a7d84941fd4/schema/provenance-2.0.cue
Even if they're correct, they're hard to read and maintain.
It probably makes sense to include some URI validation as part of the net library.
@mlieberman85 is there a package/API surface you had in mind here? Is net/url (or an equivalent thereof) sufficient?
@myitcv we discussed this exactly on Slack, in particular https://pkg.go.dev/net/url#ParseRequestURI
It would be interesting to get the structured data back as well as being able to go the opposite direction to a properly formed URI
I think a package like cue-lang.org/pkg/net, but then for URLs would indeed make a lot of sense.
I’ve recently had the need to Escape query strings in k8s configurations, which would be another nice to have in net/url. I'm thinking of creating a PR for this work but what do we think about creating a new sub-pkg in net much like encoding currently has?
Note that package net currently already has a FQDN builtin. This seems to suggest URL should be in net and not in net/url. This has the additional benefit that a URL validator builtin could be net.URL instead of url.URL. Slightly nicer.
Furthermore, the net package in Go is huge and does a lot of stuff that is unlikely to make it into the CUE library. Similarly, the net/url package doesn't have a very large API surface.
All in all, I would personally be in favor to include the URL-related functionality in net directly.
Aside from the FQDN builtin, there seems to be various overlapping concepts between the two packages, so I think this will ultimately simplify things for the user.
I believe @rogpeppe implemented this in https://review.gerrithub.io/c/cue-lang/cue/+/1202104 as part of his work in JSON Schema; is everyone here happy with that, or is there anything else remaining to be done?
@rogpeppe confirms that we can close this issue as resolved after merging the patch above :)