Skip to content

Commit 68055c1

Browse files
author
xmik
committed
Fix #37 support when the current dir contains special characters
1 parent 5b25547 commit 68055c1

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 0.12.1 (2024-Feb-05)
2+
3+
* Fix https://github.com/kudulab/dojo/issues/37 - support the case when the current directory contains special characters
4+
15
### 0.12.0 (2024-Feb-04)
26

37
* Compile Dojo using Golang 1.21.6 thanks to using Docker image kudulab/golang-dojo:2.1.0

utils.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"log"
99
"math/rand"
1010
"os"
11+
"regexp"
1112
"runtime"
1213
"strconv"
1314
"strings"
@@ -113,6 +114,9 @@ func getRunIDGenerateFromCurrentDir(currentDirectory string) string {
113114
// the currentDirectory contains capital letters and docker-compose project names do not welcome
114115
// capital letters
115116
runID = strings.ToLower(runID)
117+
//runID = strings.ReplaceAll(runID, " ", "")
118+
// remove any special characters
119+
runID = regexp.MustCompile(`[^a-zA-Z0-9\-]+`).ReplaceAllString(runID, "")
116120
return runID
117121
}
118122

utils_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,21 @@ func Test_getRunID(t *testing.T) {
106106
}
107107

108108
func Test_getRunIDGenerateFromCurrentDir(t *testing.T) {
109+
// lower case letters only
109110
runID := getRunIDGenerateFromCurrentDir("mydir")
110111
assert.True(t, strings.HasPrefix(runID, "dojo-mydir-"))
111112

113+
// lower case and upper case letters
112114
runID = getRunIDGenerateFromCurrentDir("mYdIR")
113115
assert.True(t, strings.HasPrefix(runID, "dojo-mydir-"))
116+
117+
// lower case and upper case letters and spaces
118+
runID = getRunIDGenerateFromCurrentDir("mYdIR with spaces")
119+
assert.True(t, strings.HasPrefix(runID, "dojo-mydirwithspaces-"))
120+
121+
// lower case and upper case letters and spaces and special characters
122+
runID = getRunIDGenerateFromCurrentDir("mYdIR wi#th s(3paces")
123+
assert.True(t, strings.HasPrefix(runID, "dojo-mydirwiths3paces-"))
114124
}
115125

116126
func getTestConfig() Config {

version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package main
2-
const DojoVersion = "0.12.0"
2+
const DojoVersion = "0.12.1"
33

0 commit comments

Comments
 (0)