Skip to content

Commit a857f7d

Browse files
ShashikanthRaoTGitHub Enterprise
authored andcommitted
replace special characters in qm name (#524)
1 parent ff8a0bc commit a857f7d

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

cmd/runmqserver/qmgr.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func createQueueManager(name string, devMode bool) (bool, error) {
6161
return false, err
6262
}
6363

64-
dataDir := getQueueManagerDataDir(mounts, name)
64+
dataDir := getQueueManagerDataDir(mounts, replaceCharsInQMName(name))
6565

6666
// Run 'dspmqinf' to check if 'mqs.ini' configuration file exists
6767
// If command succeeds, the queue manager (or standby queue manager) has already been created
@@ -316,7 +316,7 @@ func updateQMini(qmname string) error {
316316
log.Printf("Error getting mounts for queue manager")
317317
return err
318318
}
319-
dataDir := getQueueManagerDataDir(mounts, qmname)
319+
dataDir := getQueueManagerDataDir(mounts, replaceCharsInQMName(qmname))
320320
qmgrDir := filepath.Join(dataDir, "qm.ini")
321321
//read the initial version.
322322
// #nosec G304 - qmgrDir filepath is derived from dspmqinf
@@ -337,3 +337,17 @@ func updateQMini(qmname string) error {
337337
}
338338
return nil
339339
}
340+
341+
// If queue manager name contains a '.', then the '.' will be replaced with '!'
342+
// in the name of the data directory created by the queue manager. Similarly
343+
// '/' will be replaced with '&'.
344+
func replaceCharsInQMName(qmname string) string {
345+
replacedName := qmname
346+
if strings.Contains(replacedName, ".") {
347+
replacedName = strings.ReplaceAll(replacedName, ".", "!")
348+
}
349+
if strings.Contains(replacedName, "/") {
350+
replacedName = strings.ReplaceAll(replacedName, "/", "&")
351+
}
352+
return replacedName
353+
}

cmd/runmqserver/qmgr_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package main
1717

1818
import (
1919
"io/ioutil"
20+
"strings"
2021
"testing"
2122
)
2223

@@ -84,3 +85,38 @@ func Test_validateLogFilePageSetting(t *testing.T) {
8485
})
8586
}
8687
}
88+
89+
// Unit test for special character in queue manager names
90+
func Test_SpecialCharInQMNameReplacements(t *testing.T) {
91+
type qmNames struct {
92+
qmName string
93+
replacedQMName string
94+
}
95+
96+
tests := []qmNames{
97+
{
98+
qmName: "QM.",
99+
replacedQMName: "QM!",
100+
}, {
101+
qmName: "QM/",
102+
replacedQMName: "QM&",
103+
},
104+
{
105+
qmName: "QM.GR.NAME",
106+
replacedQMName: "QM!GR!NAME",
107+
}, {
108+
qmName: "QM/GR/NAME",
109+
replacedQMName: "QM&GR&NAME",
110+
}, {
111+
qmName: "QMGRNAME",
112+
replacedQMName: "QMGRNAME",
113+
},
114+
}
115+
116+
for _, test := range tests {
117+
replacedQMName := replaceCharsInQMName(test.qmName)
118+
if !strings.EqualFold(replacedQMName, test.replacedQMName) {
119+
t.Fatalf("QMName replacement failed. Expected %s but got %s\n", test.replacedQMName, replacedQMName)
120+
}
121+
}
122+
}

0 commit comments

Comments
 (0)