Skip to content
Merged
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
12 changes: 7 additions & 5 deletions internal/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ const (
)

var (
pkgNameRe = regexp.MustCompile(`^[a-zA-Z0-9@/_.-]+$`)
tapNameRe = regexp.MustCompile(`^[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+$`)
domainKeyRe = regexp.MustCompile(`^[a-zA-Z0-9 ._-]+$`)
pkgNameRe = regexp.MustCompile(`^[a-zA-Z0-9@/_.-]+$`)
tapNameRe = regexp.MustCompile(`^[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+$`)
// macOS preference domains never contain spaces; keys may (e.g. "NSStatusItem Visible Sound").
domainRe = regexp.MustCompile(`^[a-zA-Z0-9._-]+$`)
keyRe = regexp.MustCompile(`^[a-zA-Z0-9 ._-]+$`)

// dotfilesPathRe validates the path component: one or more segments of
// alphanumeric, dash, underscore, or dot characters separated by slashes.
Expand Down Expand Up @@ -126,10 +128,10 @@ func validateMacOSPrefs(rc *RemoteConfig) error {
if strings.HasPrefix(mp.Key, "-") {
return fmt.Errorf("invalid macos_prefs key: %q must not start with '-'", mp.Key)
}
if !domainKeyRe.MatchString(mp.Domain) {
if !domainRe.MatchString(mp.Domain) {
return fmt.Errorf("macos preference domain %q contains invalid characters", mp.Domain)
}
if !domainKeyRe.MatchString(mp.Key) {
if !keyRe.MatchString(mp.Key) {
return fmt.Errorf("macos preference key %q contains invalid characters", mp.Key)
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/config/validate_extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestValidateMacOSPrefs_KeyStartsWithDash(t *testing.T) {
func TestValidateMacOSPrefs_InvalidDomainCharacters(t *testing.T) {
rc := &RemoteConfig{
MacOSPrefs: []RemoteMacOSPref{
{Domain: "com.apple;dock", Key: "autohide", Type: "bool"},
{Domain: "com.apple dock", Key: "autohide", Type: "bool"},
},
}
err := validateMacOSPrefs(rc)
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestValidateMacOSPrefs_KeyWithSpaces(t *testing.T) {
}

func TestValidateMacOSPrefs_DomainWithSpecialValidChars(t *testing.T) {
// Domain and key regex: [a-zA-Z0-9 ._-]+
// domainRe: [a-zA-Z0-9._-]+ keyRe: [a-zA-Z0-9 ._-]+
validDomains := []string{
"com.apple.dock",
"NSGlobalDomain",
Expand Down
Loading