#```console
1 messages ยท Page 1 of 1 (latest)
guessing
ssh://git@github.com/shykes/daggerverse ๐ช
% git remote -v
origin ssh://git@github.com/shykes/daggerverse (fetch)
origin ssh://git@github.com/shykes/daggerverse (push)
Note, I didn't touch my remotes recently. First time I get this error on dagger mod publish (usually it just happily returns, and does nothing)
Yeah I'm trying to decide if it's worth just expanding the regex further or find some better way
"Write a regex that accounts for every possible git url format" sounds like a form of torture
on it
there hasto be a library somewhere for this, just need to find it
To create a regex pattern for the secure Git URL formats from the given sections, we would need to capture:
- Local Filesystem Paths: Both absolute and relative paths.
- HTTP(S): Only
https://since it's the secure version. - SSH: Both full and shorthand versions.
Here's a regex pattern that should capture those:
^(\/[^\s]+|https:\/\/[a-zA-Z0-9.-]+(\/[^\s]*)?|ssh:\/\/[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+(:[0-9]+)?(\/[^\s]*)?|[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+:(\/?[^\s]+)?)$
This regex assumes:
- A local path starting with
/. - URLs with valid characters (like alphanumeric characters, dots, hyphens).
- SSH usernames and hostnames with valid characters.
Breakdown:
^(\/[^\s]+: Matches absolute paths.https:\/\/[a-zA-Z0-9.-]+(\/[^\s]*)?: Matcheshttps://URLs.ssh:\/\/[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+(:[0-9]+)?(\/[^\s]*)?: Matches full SSH URLs.[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+:(\/?[^\s]+)?: Matches shorthand SSH URLs.
However, this regex does have some limitations:
- It doesn't fully validate domain names or URLs.
- It assumes that a valid SSH username or hostname doesn't have special characters except
._%-.
Always remember, while regex can help validate structure, it doesn't guarantee the functionality or authenticity of a URL. Always validate and sanitize user input in applications and use safe methods to clone or interact with Git URLs.
Ended up just using a lib for the parsing part so we should handle all the cases now: https://github.com/dagger/dagger/pull/6053
The chatgpt one was close but slightly off and I didn't want to try editing that regex ๐