Merge pull request #130 from stevvooe/path-names-escaped
Prefix non-name path components
This commit is contained in:
commit
d91e4bc34d
4 changed files with 61 additions and 40 deletions
|
@ -78,12 +78,12 @@ type StorageDriver interface {
|
|||
URLFor(path string, options map[string]interface{}) (string, error)
|
||||
}
|
||||
|
||||
// PathRegexp is the regular expression which each file path must match.
|
||||
// A file path is absolute, beginning with a slash and containing a
|
||||
// positive number of path components separated by slashes, where each component
|
||||
// is restricted to lowercase alphanumeric characters, optionally separated by
|
||||
// a period, underscore, or hyphen.
|
||||
var PathRegexp = regexp.MustCompile(`^(/[a-z0-9]+([._-][a-z0-9]+)*)+$`)
|
||||
// PathRegexp is the regular expression which each file path must match. A
|
||||
// file path is absolute, beginning with a slash and containing a positive
|
||||
// number of path components separated by slashes, where each component is
|
||||
// restricted to lowercase alphanumeric characters or a period, underscore, or
|
||||
// hyphen.
|
||||
var PathRegexp = regexp.MustCompile(`^(/[a-z0-9._-]+)+$`)
|
||||
|
||||
// UnsupportedMethodErr may be returned in the case where a StorageDriver implementation does not support an optional method.
|
||||
var ErrUnsupportedMethod = errors.New("Unsupported method")
|
||||
|
|
|
@ -123,7 +123,21 @@ func (suite *DriverSuite) TearDownTest(c *check.C) {
|
|||
// storage driver.
|
||||
func (suite *DriverSuite) TestValidPaths(c *check.C) {
|
||||
contents := randomContents(64)
|
||||
validFiles := []string{"/a", "/2", "/aa", "/a.a", "/0-9/abcdefg", "/abcdefg/z.75", "/abc/1.2.3.4.5-6_zyx/123.z/4", "/docker/docker-registry"}
|
||||
validFiles := []string{
|
||||
"/a",
|
||||
"/2",
|
||||
"/aa",
|
||||
"/a.a",
|
||||
"/0-9/abcdefg",
|
||||
"/abcdefg/z.75",
|
||||
"/abc/1.2.3.4.5-6_zyx/123.z/4",
|
||||
"/docker/docker-registry",
|
||||
"/123.abc",
|
||||
"/abc./abc",
|
||||
"/.abc",
|
||||
"/a--b",
|
||||
"/a-.b",
|
||||
"/_.abc"}
|
||||
|
||||
for _, filename := range validFiles {
|
||||
err := suite.StorageDriver.PutContent(filename, contents)
|
||||
|
@ -140,7 +154,14 @@ func (suite *DriverSuite) TestValidPaths(c *check.C) {
|
|||
// storage driver.
|
||||
func (suite *DriverSuite) TestInvalidPaths(c *check.C) {
|
||||
contents := randomContents(64)
|
||||
invalidFiles := []string{"", "/", "abc", "123.abc", "/abc./abc", "/.abc", "/a--b", "/a-.b", "/_.abc", "//bcd", "/abc_123/", "/Docker/docker-registry"}
|
||||
invalidFiles := []string{
|
||||
"",
|
||||
"/",
|
||||
"abc",
|
||||
"123.abc",
|
||||
"//bcd",
|
||||
"/abc_123/",
|
||||
"/Docker/docker-registry"}
|
||||
|
||||
for _, filename := range invalidFiles {
|
||||
err := suite.StorageDriver.PutContent(filename, contents)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue