Skip to content

Commit bb4aeca

Browse files
committed
ADD: support for paths started with slash and replace dot by slashs
1 parent c4519b6 commit bb4aeca

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/utils/custom_path.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ func GetAllCustomPaths() *[]CustomPath {
4343
splitVar := strings.Split(variable, "=")
4444

4545
newPath := strings.ReplaceAll(splitVar[0], "GHS_CUSTOM_PATH_", "")
46+
47+
if strings.HasPrefix(newPath, "/") {
48+
newPath = newPath[1:len(newPath)]
49+
}
4650
if len(splitVar) > 1 {
4751
varObject := CustomPath{
48-
path: newPath,
52+
path: strings.ReplaceAll(newPath, ".", "/"),
4953
target: splitVar[1],
5054
rewrite: checkIfEnvVariableIsSet(envVars, fmt.Sprintf("GHS_CUSTOM_REWRITE_%s", newPath)),
5155
}

src/utils/custom_path_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ import (
1111
func TestGetAllCustomPaths(t *testing.T) {
1212
os.Setenv("GHS_CUSTOM_PATH_images/digilex-infordoc-images", "https://storage.gra.cloud.ovh.net/v1/AUTH_ed33ec9e34c64b54aca49d6fcb6dc4c8/infordoc-img")
1313
os.Setenv("GHS_CUSTOM_REWRITE_images/digilex-infordoc-images", "")
14-
os.Setenv("GHS_CUSTOM_PATH_images/digilex-infordoc-images-1", "https://storage.gra.cloud.ovh.net/v1/AUTH_ed33ec9e34c64b54aca49d6fcb6dc4c8/img")
15-
os.Setenv("GHS_CUSTOM_PATH_images/digilex-infordoc-images-2", "https://storage.gra.cloud.ovh.net/v1/AUTH_ed33ec9e34c64b54aca49d6fcb6dc4c8/infordoc")
14+
os.Setenv("GHS_CUSTOM_PATH_images.digilex-infordoc-images-1", "https://storage.gra.cloud.ovh.net/v1/AUTH_ed33ec9e34c64b54aca49d6fcb6dc4c8/img")
15+
os.Setenv("GHS_CUSTOM_PATH_/images/digilex-infordoc-images-2", "https://storage.gra.cloud.ovh.net/v1/AUTH_ed33ec9e34c64b54aca49d6fcb6dc4c8/infordoc")
1616
result := GetCustomPathsInstance()
1717

1818
assert.True(t, len(*result) == 3)
1919

2020
for _, customVar := range *result {
2121
log.Printf("Path: %s - Target: %s - Rewrite: %t \n", customVar.GetPath(), customVar.GetTarget(), customVar.IsRewrite())
2222
assert.False(t, strings.HasPrefix(customVar.path, "GHS_CUSTOM_PATH_"))
23-
23+
assert.False(t, strings.HasPrefix(customVar.path, "/"))
24+
assert.True(t, strings.Contains(customVar.path, "/"))
2425
}
2526

2627
}

0 commit comments

Comments
 (0)