Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix replication of multiple projects with numeric names #21474

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/lib/q/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,22 @@ func parseList(value string, c rune) ([]interface{}, error) {

// try to parse value as time first, then integer, and last string
func parseValue(value string) interface{} {
var ret any
value = strings.TrimSpace(value)
// try to parse time
time, err := time.Parse("2006-01-02T15:04:05", value)
if err == nil {
return time
}
// try to parse integer
i, err := strconv.ParseInt(value, 10, 64)
if err == nil {
return i
}
// if the value isn't time and integer, treat it as string
return strings.Trim(value, `"'`)

// try parsing as different value types
if time, err := time.Parse("2006-01-02T15:04:05", value); err == nil {
// parsed as time value
ret = time
} else if i, err := strconv.ParseInt(value, 10, 64); err == nil {
// parsed as integer value
ret = i
} else {
// no other parsing worked, treat as a string value
ret = strings.Trim(value, `"'`)
}
log.Debugf(`parsed %s as '%T' value: %v`, value, ret, ret)
return ret
}

// escape the special character
Expand Down
9 changes: 6 additions & 3 deletions src/pkg/reg/adapter/harbor/base/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,15 @@ func (a *Adapter) PrepareForPush(resources []*model.Resource) error {
}
}

// Create a list of the project names.
var ps []string
for p := range projects {
ps = append(ps, p)
// Surround name in 'quotes' to force the server to parse as a string.
// Handles the case where a project name consists entirely of numbers.
ps = append(ps, fmt.Sprintf("'%s'", p))
}
// query by project name, decorate the name as string to avoid parsed as int by server in case of pure numbers as project name
q := fmt.Sprintf("name={'%s'}", strings.Join(ps, " "))
// query by project names
q := fmt.Sprintf("name={%s}", strings.Join(ps, " "))
// get exist projects
queryProjects, err := a.Client.ListProjectsWithQuery(q, false)
if err != nil {
Expand Down
Loading