Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Unified Diff: cipd/client/cipd/ensure/file.go

Issue 2651173003: [cipd] Move ValidateRoot to common package (Closed)
Patch Set: Add test Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cipd/client/cipd/common/common_test.go ('k') | cipd/client/cipd/ensure/item_parsers.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cipd/client/cipd/ensure/file.go
diff --git a/cipd/client/cipd/ensure/file.go b/cipd/client/cipd/ensure/file.go
index 2fce231da88ce5233de95866c1fd1b47c1d2497a..5e3eab184f0464178f0d22abe8fa3575f6f17783 100644
--- a/cipd/client/cipd/ensure/file.go
+++ b/cipd/client/cipd/ensure/file.go
@@ -10,7 +10,6 @@ import (
"fmt"
"io"
"net/url"
- "path"
"sort"
"strings"
@@ -26,29 +25,6 @@ type File struct {
PackagesByRoot map[string]PackageSlice
}
-// ValidateRoot ensures that the given root is valid.
-func ValidateRoot(root string) error {
- if root == "" { // empty is fine
- return nil
- }
- if strings.Contains(root, "\\") {
- return fmt.Errorf(`bad root path: backslashes not allowed (use "/"): %q`, root)
- }
- if strings.Contains(root, ":") {
- return fmt.Errorf(`bad root path: colons are not allowed: %q`, root)
- }
- if cleaned := path.Clean(root); cleaned != root {
- return fmt.Errorf("bad root path: %q (should be %q)", root, cleaned)
- }
- if strings.HasPrefix(root, "./") || strings.HasPrefix(root, "../") || root == "." {
- return fmt.Errorf(`bad root path: invalid ".": %q`, root)
- }
- if strings.HasPrefix(root, "/") {
- return fmt.Errorf("bad root path: absolute paths not allowed: %q", root)
- }
- return nil
-}
-
// ParseFile parses an ensure file from the given reader. See the package docs
// for the format of this file.
//
@@ -171,7 +147,7 @@ func (f *File) ResolveWith(arch, plat string, rslv VersionResolver) (*ResolvedFi
ret.PackagesByRoot = map[string][]common.Pin{}
for root, pkgs := range f.PackagesByRoot {
// double-check the root
- if err := ValidateRoot(root); err != nil {
+ if err := common.ValidateRoot(root); err != nil {
return nil, errors.Annotate(err).
Reason("normalizing %(root)q").
D("root", root).
« no previous file with comments | « cipd/client/cipd/common/common_test.go ('k') | cipd/client/cipd/ensure/item_parsers.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698