/srv/irclogs.ubuntu.com/2021/01/22/#launchpad.txt

rbasakI'm writing some input validation for git urls and refs in changes files. Any tips? Launchpad-specific: is there a list of things anywhere like valid username characters, project name characters, and so on?14:29
rbasak(this matters because I'm having to use subprocess.check_call() instead of speaking to pygit2 directly, because pygit2 doesn't support fetching refs from an arbitrary URL like the git CLI does, and temporarily adding a remote is also awkward.14:30
rbasak)14:30
cjwatsonFor refs we intend to support everything git supports, which is documented in git-check-ref-format(1)15:11
rbasakAha15:12
cjwatsonUsername validation is in lp.app.validators.name but not I think publicly documented15:12
rbasakI had failed to find that. Thank you!15:12
cjwatsonI don't get the connection to subprocess.check_call though.  I'd have thought any necessary validation would be the same either way, and if it's not then that would imply a quoting problem15:12
rbasakPerhaps I'm being overly paranoid15:13
cjwatsonDefinitely don't get why you'd need to do independent username validation.  Either the URL exists or it doesn't15:13
rbasakI'm just trying to make sure I don't accidentally pass something through to git that it'll somehow interpret differently15:13
cjwatsonI would focus on quoting rather than validation, I think15:13
rbasakFor example, if a ref contains a colon, then "git fetch <url> <ref>" will overwrite some arbitrary local ref, which I don't want.15:14
cjwatson(by which I don't mean literally '' or "", but more generally the task of unparsing accurately)15:14
cjwatsonRight, there may be some things you need to reject15:14
rbasakI'm using shell=False to subprocess.check_call, so I shouldn't need to quote through a shell.15:14
rbasakSo being paranoid I'm starting narrow and only allowing what I explicitly understand to be acceptable15:15
cjwatsonIt would be fine to validate at least some of the rules in git-check-ref-format(1) independently IMO, since those do help avoid ambiguities.15:15
cjwatsonBut for URLs I wouldn't do more than basic "is this syntactically a URL at all?" sort of validation, plus suitable unparsing15:16
cjwatson(Do you know what I mean by unparsing?  I came across the term a while back, find it useful, but I don't know how common it is)15:16
rbasakI don't.15:16
rbasakgit handles some "URLs" specially too - for example git-remote-ext(1) will accept "ext::<command>[ <arguments>...]" which looks scary15:17
cjwatsonIt's the idea that when you're preparing input to a tool that does some kind of parsing of input, you often want to precisely reverse whatever parsing that tool will do in order to make sure that you can successfully pass literal values through15:17
cjwatsonQuoting is one form of that15:17
rbasakI see, thanks.15:17
cjwatsonYeah, you might want to limit URL schemes to just git+ssh and https15:18
cjwatsonI agree that arbitrary schemes could in principle do weird stuff15:19
cjwatsonpygit2 does have some odd omissions15:20
cjwatsonI might have gone for temporarily adding a remote, but I can see why you might not want to15:22
cjwatsonMight also be worth chatting to pygit2 upstream15:23
cjwatsonI've generally found them helpful, though haven't had to deal with them much15:24
cjwatsonBeing able to have an ephemeral anonymous remote seems handy15:24
rbasakI filed https://github.com/libgit2/pygit2/issues/1060 and left it at that15:25
cjwatsonAh yes15:25

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!