From 68b9eddaf166bfd46ae67dbf76ea5cf158cb027d Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Wed, 15 May 2019 06:37:07 +0200 Subject: [PATCH] Fix escaping of '?' character in shell alias Fixes #275. --- modulecmd.tcl.in | 4 ++-- testsuite/install.00-init/020-module.exp | 2 +- testsuite/modulefiles/alias/3.0 | 2 ++ testsuite/modules.00-init/006-procs.exp | 2 +- testsuite/modules.50-cmds/076-alias-sub.exp | 3 +++ 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modulecmd.tcl.in b/modulecmd.tcl.in index 6f122606..8ae26d6f 100644 --- a/modulecmd.tcl.in +++ b/modulecmd.tcl.in @@ -5749,11 +5749,11 @@ proc resolveModuleVersionOrAlias {name} { return $ret } -proc charEscaped {str {charlist { \\\t\{\}|<>!;#^$&*"'`()}}} { +proc charEscaped {str {charlist { \\\t\{\}|<>!;#^$&*?"'`()}}} { return [regsub -all "\(\[$charlist\]\)" $str {\\\1}] } -proc charUnescaped {str {charlist { \\\t\{\}|<>!;#^$&*"'`()}}} { +proc charUnescaped {str {charlist { \\\t\{\}|<>!;#^$&*?"'`()}}} { return [regsub -all "\\\\\(\[$charlist\]\)" $str {\1}] } diff --git a/testsuite/install.00-init/020-module.exp b/testsuite/install.00-init/020-module.exp index e6e61166..2c300efa 100644 --- a/testsuite/install.00-init/020-module.exp +++ b/testsuite/install.00-init/020-module.exp @@ -44,7 +44,7 @@ foreach shell $shell_list { # ensure tools used in complex shell alias definition are available if {[find_bin grep] ne "" && [find_bin tr] ne "" && [find_bin awk] ne ""} { foreach shell $shell_list { - testall_cmd_re "$shell" "module load $testsuite_modpath/alias/3.0\; testsuite" "Release" ".*" 0 + testall_cmd_re "$shell" "module load $testsuite_modpath/alias/3.0\; testsuite; ts2" "Release\nhttp://an.example.web\\?¶m=one" ".*" 0 } } elseif {$verbose > 0} { send_user "\tSkipping shell alias definition tests\n" diff --git a/testsuite/modulefiles/alias/3.0 b/testsuite/modulefiles/alias/3.0 index d3863d1c..e1535eea 100644 --- a/testsuite/modulefiles/alias/3.0 +++ b/testsuite/modulefiles/alias/3.0 @@ -33,3 +33,5 @@ switch -- [module-info shelltype] { } } +# check '?' and '&' are correctly escaped +set-alias ts2 {echo "http://an.example.web?¶m=one"} diff --git a/testsuite/modules.00-init/006-procs.exp b/testsuite/modules.00-init/006-procs.exp index 81fd4bab..04d9a3e1 100644 --- a/testsuite/modules.00-init/006-procs.exp +++ b/testsuite/modules.00-init/006-procs.exp @@ -219,7 +219,7 @@ proc shell_val {test_shell val {re_mode 0}} { if {$val ne "(.*)"} { switch -- $test_shell { {sh} - {bash} - {ksh} - {zsh} - {csh} - {tcsh} - {fish} { - set val [regsub -all {([\\"'$|{}`* ()!&])} $val {\\\1}] + set val [regsub -all {([\\"'$|{}`*? ()!&])} $val {\\\1}] } {lisp} - {cmake} { set val [regsub -all {(["])} $val {\\\1}] diff --git a/testsuite/modules.50-cmds/076-alias-sub.exp b/testsuite/modules.50-cmds/076-alias-sub.exp index ebdbcb87..45764318 100644 --- a/testsuite/modules.50-cmds/076-alias-sub.exp +++ b/testsuite/modules.50-cmds/076-alias-sub.exp @@ -76,16 +76,19 @@ set modulefile "$modpath/$module" set ans [list] lappend ans [list alias testsuite {echo $(grep "report .Modules " modulecmd.tcl | tr -d \\ | awk '{print $3}')}] +lappend ans [list alias ts2 {echo "http://an.example.web?¶m=one"}] lappend ans [list setpath LOADEDMODULES $module] lappend ans [list setpath _LMFILES_ $modulefile] set ans2 [list] lappend ans2 [list alias testsuite {echo `grep "report .Modules " modulecmd.tcl | tr -d \\ | awk '{print $3}'`}] +lappend ans2 [list alias ts2 {echo "http://an.example.web?¶m=one"}] lappend ans2 [list setpath LOADEDMODULES $module] lappend ans2 [list setpath _LMFILES_ $modulefile] set ans3 [list] lappend ans3 [list alias testsuite {echo (grep "report .Modules " modulecmd.tcl | tr -d \\ | awk '{print $3}')}] +lappend ans3 [list alias ts2 {echo "http://an.example.web?¶m=one"}] lappend ans3 [list setpath LOADEDMODULES $module] lappend ans3 [list setpath _LMFILES_ $modulefile]