-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from chaws/fix-paths
installer: normalize paths
- Loading branch information
Showing
5 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
/* Copyright Contributors to the cpackget project. */ | ||
|
||
package installer_test | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func generatePaths(t *testing.T) map[string]string { | ||
cwd, err := os.Getwd() | ||
assert.Nil(t, err) | ||
|
||
dirName := "valid-pack-root" | ||
absPath := filepath.Join(cwd, dirName) | ||
|
||
// Define a few paths to try out | ||
return map[string]string{ | ||
"regular absolute path": absPath, | ||
"absolute path with ..": filepath.Join(absPath, "..", dirName), | ||
"multiple leading slashes": "////" + absPath, | ||
"multiple trailing slashes": absPath + "////", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
/* Copyright Contributors to the cpackget project. */ | ||
|
||
package installer_test | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func generatePaths(t *testing.T) map[string]string { | ||
cwd, err := os.Getwd() | ||
assert.Nil(t, err) | ||
|
||
dirName := "valid-pack-root" | ||
absPath := filepath.Join(cwd, dirName) | ||
|
||
// Define a few paths to try out | ||
return map[string]string{ | ||
"regular absolute path": absPath, | ||
"absolute path with ..": filepath.Join(absPath, "..", dirName), | ||
"absolute path with :/": strings.Replace(absPath, ":\\", "/", 1), | ||
"all forward slashes": strings.ReplaceAll(absPath, "\\", "/"), | ||
"multiple leading slashes": strings.Replace(absPath, ":\\", ":\\\\\\\\", 1), | ||
"multiple trailing slashes": absPath + "\\\\\\\\", | ||
} | ||
} |