cue icon indicating copy to clipboard operation
cue copied to clipboard

pkg: URI validation

Open mlieberman85 opened this issue 4 years ago • 6 comments

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 avatar Dec 14 '21 21:12 mlieberman85

@mlieberman85 is there a package/API surface you had in mind here? Is net/url (or an equivalent thereof) sufficient?

myitcv avatar Dec 15 '21 05:12 myitcv

@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

verdverm avatar Dec 15 '21 11:12 verdverm

I think a package like cue-lang.org/pkg/net, but then for URLs would indeed make a lot of sense.

mpvl avatar Dec 16 '21 09:12 mpvl

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?

lugoues avatar Jan 05 '22 06:01 lugoues

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.

mpvl avatar Jan 15 '22 14:01 mpvl

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?

mvdan avatar Oct 10 '24 21:10 mvdan

@rogpeppe confirms that we can close this issue as resolved after merging the patch above :)

mvdan avatar Oct 21 '24 14:10 mvdan