Skip to content

Commit f31d010

Browse files
committed
Escape [ and ] used in values within produced shell code
Square brackets may have special meaning on some shells (like csh), so they should be escaped. Fixes #565
1 parent 2ccffda commit f31d010

File tree

7 files changed

+15
-7
lines changed

7 files changed

+15
-7
lines changed

NEWS.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Modules 5.6.0 (not yet released)
2626
* Doc: add :ref:`acknowledgments` page in the documentation.
2727
* Doc: describe :ref:`GOVERNANCE`.
2828
* Doc: add :ref:`CHARTER`.
29+
* Escape square brackets (``[]``) used in values within produced shell code as
30+
these characters may have special meaning on some shells (like *csh*). (fix
31+
issue #565)
2932

3033
.. _Security policy: https://github.com/envmodules/modules/blob/main/SECURITY.md
3134

tcl/util.tcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020

2121
##########################################################################
2222

23-
proc charEscaped {str {charlist " \\\\\t{}|<>!;#^\$&*?\"'`()"}} {
23+
proc charEscaped {str {charlist " \\\\\t{}\\\[\\\]|<>!;#^\$&*?\"'`()"}} {
2424
return [regsub -all "\(\[$charlist\]\)" $str {\\\1}]
2525
}
2626

27-
proc charUnescaped {str {charlist " \\\\\t{}|<>!;#^\$&*?\"'`()"}} {
27+
proc charUnescaped {str {charlist " \\\\\t{}\\\[\\\]|<>!;#^\$&*?\"'`()"}} {
2828
return [regsub -all "\\\\\(\[$charlist\]\)" $str {\1}]
2929
}
3030

testsuite/config/base-config.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ proc shell_val {test_shell val {re_mode 0}} {
234234
if {$val ne "(.*)"} {
235235
switch -- $test_shell {
236236
{sh} - {bash} - {ksh} - {zsh} - {csh} - {tcsh} - {fish} {
237-
set val [regsub -all {([\\"'$|<>{}`*? ()!&;])} $val {\\\1}]
237+
set val [regsub -all {([\\"'$|<>{}`*? ()!&;\[\]])} $val {\\\1}]
238238
}
239239
{lisp} - {cmake} {
240240
set val [regsub -all {(["])} $val {\\\1}]

testsuite/install.00-init/020-module.exp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ if {[find_bin grep] ne "" && [find_bin tr] ne "" && [find_bin awk] ne ""} {
4747
foreach shell $shell_list {
4848
if {$shell eq {csh} || $shell eq {tcsh}} {
4949
# alias evaluation leads to a syntax error if wa_277 is enabled
50-
testall_cmd_re "$shell" "module load $testsuite_modpath/alias/3.0\; testsuite; ts2" [expr {$install_wa277 eq {y} ? {} : "Release\nhttp://an.example.web\\?&param=one"}] ".*" [expr {$install_wa277 eq {y} ? 1 : 0}]
50+
testall_cmd_re "$shell" "module load $testsuite_modpath/alias/3.0\; testsuite; ts2; ts3" [expr {$install_wa277 eq {y} ? {} : "Release\nhttp://an.example.web\\?&param=one\nselect\\\[type==BAR && osrel==FOO\\\] myapp"}] ".*" [expr {$install_wa277 eq {y} ? 1 : 0}]
5151
} else {
52-
testall_cmd_re "$shell" "module load $testsuite_modpath/alias/3.0\; testsuite; ts2" "Release\nhttp://an.example.web\\?&param=one" ".*" 0
52+
testall_cmd_re "$shell" "module load $testsuite_modpath/alias/3.0\; testsuite; ts2; ts3" "Release\nhttp://an.example.web\\?&param=one\nselect\\\[type==BAR && osrel==FOO\\\] myapp" ".*" 0
5353
}
5454
}
5555
} elseif {$verbose} {

testsuite/install.00-init/024-ml.exp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ if {[find_bin grep] ne "" && [find_bin tr] ne "" && [find_bin awk] ne ""} {
5050
foreach shell $shell_list {
5151
if {$shell eq {csh} || $shell eq {tcsh}} {
5252
# alias evaluation leads to a syntax error if wa_277 is enabled
53-
testall_cmd_re "$shell" "ml $testsuite_modpath/alias/3.0\; testsuite; ts2" [expr {$install_wa277 eq {y} ? {} : "Release\nhttp://an.example.web\\?&param=one"}] ".*" [expr {$install_wa277 eq {y} ? 1 : 0}]
53+
testall_cmd_re "$shell" "ml $testsuite_modpath/alias/3.0\; testsuite; ts2; ts3" [expr {$install_wa277 eq {y} ? {} : "Release\nhttp://an.example.web\\?&param=one\nselect\\\[type==BAR && osrel==FOO\\\] myapp"}] ".*" [expr {$install_wa277 eq {y} ? 1 : 0}]
5454
} else {
55-
testall_cmd_re "$shell" "ml $testsuite_modpath/alias/3.0\; testsuite; ts2" "Release\nhttp://an.example.web\\?&param=one" ".*" 0
55+
testall_cmd_re "$shell" "ml $testsuite_modpath/alias/3.0\; testsuite; ts2; ts3" "Release\nhttp://an.example.web\\?&param=one\nselect\\\[type==BAR && osrel==FOO\\\] myapp" ".*" 0
5656
}
5757
}
5858
} elseif {$verbose} {

testsuite/modulefiles/alias/3.0

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ switch -- [module-info shelltype] {
3838

3939
# check '?' and '&' are correctly escaped
4040
set-alias ts2 {echo "http://an.example.web?&param=one"}
41+
# check '[' and ']' are correctly escaped
42+
set-alias ts3 "echo \"select\[type==BAR && osrel==FOO\]\" myapp"

testsuite/modules.50-cmds/076-alias-sub.exp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,23 @@ lappend ans [list set __MODULES_LMREFRESH $module]
8787
lappend ans [list set _LMFILES_ $modulefile]
8888
lappend ans [list set LOADEDMODULES $module]
8989
lappend ans [list alias ts2 {echo "http://an.example.web?&param=one"}]
90+
lappend ans [list alias ts3 {echo "select[type==BAR && osrel==FOO]" myapp}]
9091
lappend ans [list alias testsuite {echo $(grep "report .Modules " modulecmd.tcl | tr -d \\ | awk '{print $3}')}]
9192

9293
set ans2 [list]
9394
lappend ans2 [list set __MODULES_LMREFRESH $module]
9495
lappend ans2 [list set _LMFILES_ $modulefile]
9596
lappend ans2 [list set LOADEDMODULES $module]
9697
lappend ans2 [list alias ts2 {echo "http://an.example.web?&param=one"}]
98+
lappend ans2 [list alias ts3 {echo "select[type==BAR && osrel==FOO]" myapp}]
9799
lappend ans2 [list alias testsuite {echo `grep "report .Modules " modulecmd.tcl | tr -d \\ | awk '{print $3}'`}]
98100

99101
set ans3 [list]
100102
lappend ans3 [list set __MODULES_LMREFRESH $module]
101103
lappend ans3 [list set _LMFILES_ $modulefile]
102104
lappend ans3 [list set LOADEDMODULES $module]
103105
lappend ans3 [list alias ts2 {echo "http://an.example.web?&param=one"}]
106+
lappend ans3 [list alias ts3 {echo "select[type==BAR && osrel==FOO]" myapp}]
104107
lappend ans3 [list alias testsuite {echo (grep "report .Modules " modulecmd.tcl | tr -d \\ | awk '{print $3}')}]
105108

106109

0 commit comments

Comments
 (0)