mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
fix(ref): treat X#N as a reference only when X names a repository
Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
2 files changed
+12
-2
No files matched your search
@@ -55,6 +55,10 @@ func parseRef(raw string, kind refKind) (ref, error) {
|
||||
if !hashed {
|
||||
repo, value = "", raw
|
||||
}
|
||||
// Only a repository before # makes a reference, so a branch such as fix#12 stays a branch.
|
||||
if repo != "" && !repositoryLike(repo) {
|
||||
return ref{}, errNotRef
|
||||
}
|
||||
n, err := strconv.ParseInt(value, 10, 64)
|
||||
if err != nil && !hashed {
|
||||
return ref{}, errNotRef
|
||||
@@ -65,6 +69,12 @@ func parseRef(raw string, kind refKind) (ref, error) {
|
||||
return ref{Number: n, Repo: repo}, nil
|
||||
}
|
||||
|
||||
// repositoryLike reports whether raw has the form OWNER/REPO or HOST/OWNER/REPO.
|
||||
func repositoryLike(raw string) bool {
|
||||
pieces := strings.Split(raw, "/")
|
||||
return len(pieces) >= 2 && settings.ValidSlug(strings.Join(pieces[len(pieces)-2:], "/"))
|
||||
}
|
||||
|
||||
func parseRefURL(raw string, kind refKind) (ref, error) {
|
||||
invalid := clierr.Wrap(clierr.Usage, fmt.Errorf("%q is not %s URL; use %s", raw, kind.article(), kind.forms()))
|
||||
u, err := url.Parse(raw)
|
||||
|
||||
Reference in new issue
Block a user