From 339d5444954634a70b41c3908fc263cf1ee83a32 Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Tue, 2 Jun 2026 16:16:50 +0200 Subject: [PATCH] Add -encoding option to superseded source command Fix superseding definition of "source" Tcl command when "source_cache" configuration option is enabled to support "-encoding" option. The value set to this encoding option is currently ignored. Closes #627 Signed-off-by: Xavier Delaruelle --- NEWS.rst | 3 +++ tcl/mfcmd.tcl | 18 +++++++++++++- testsuite/modulefiles.4/source/1.0 | 12 ++++++++++ testsuite/modulefiles.4/source/source_file | 3 +++ .../modules.50-cmds/620-source_cache.exp | 24 +++++++++++++++++++ 5 files changed, 59 insertions(+), 1 deletion(-) diff --git a/NEWS.rst b/NEWS.rst index bec05677c..0ab016a86 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -73,6 +73,9 @@ Modules 5.7.0 (not yet released) * Improve the performance of the module’s column output by removing the costly optimization that attempts to fit more columns within the available screen width. (fix issue #622) +* Fix superseding definition of ``source`` Tcl command when + :mconfig:`source_cache` configuration option is enabled to support + ``-encoding`` option. (fix issue #627) .. _5.6 release notes: diff --git a/tcl/mfcmd.tcl b/tcl/mfcmd.tcl index efa0be1a6..4495f47c7 100644 --- a/tcl/mfcmd.tcl +++ b/tcl/mfcmd.tcl @@ -2278,7 +2278,23 @@ proc unique-name-conflict {} { conflict {*}$root_name_list } -proc sourceModfileCmd {itrp filename} { +proc sourceModfileCmd {itrp args} { + # argument parsing: catch encoding arg but ignore it + switch -- [llength $args] { + 1 {} + 3 { + set option [lindex $args 0] + if {$option ne {-encoding}} { + knerror "Invalid option '$option'" + } + } + default { + knerror {wrong # args: should be "source ?-encoding? ?encodingName?\ + fileName"} + } + } + set filename [lindex $args end] + if {![info exists ::source_cache($filename)]} { set ::source_cache($filename) [readFile $filename] } diff --git a/testsuite/modulefiles.4/source/1.0 b/testsuite/modulefiles.4/source/1.0 index 8e51b350e..6add91c6b 100644 --- a/testsuite/modulefiles.4/source/1.0 +++ b/testsuite/modulefiles.4/source/1.0 @@ -31,5 +31,17 @@ if {[info exists env(TESTSUITE_SOURCE_CACHE)]} { source ../path/to/unk setenv VAR bar } + arg1 { + source -encoding utf-8 [file dirname $ModulesCurrentModulefile]/source_file + } + bad_arg1 { + source -encoding [file dirname $ModulesCurrentModulefile]/source_file + } + bad_arg2 { + source -foo bar [file dirname $ModulesCurrentModulefile]/source_file + } + bad_arg3 { + source -encoding utf-8 -foo bar [file dirname $ModulesCurrentModulefile]/source_file + } } } diff --git a/testsuite/modulefiles.4/source/source_file b/testsuite/modulefiles.4/source/source_file index 239c4d8d5..4dfa9b00f 100644 --- a/testsuite/modulefiles.4/source/source_file +++ b/testsuite/modulefiles.4/source/source_file @@ -40,5 +40,8 @@ if {[info exists env(TESTSUITE_SOURCE_CACHE)]} { break1 { break } + arg1 - bad_arg1 - bad_arg2 { + setenv VAR bar + } } } diff --git a/testsuite/modules.50-cmds/620-source_cache.exp b/testsuite/modules.50-cmds/620-source_cache.exp index 93f02c063..a9861fec0 100644 --- a/testsuite/modules.50-cmds/620-source_cache.exp +++ b/testsuite/modules.50-cmds/620-source_cache.exp @@ -290,6 +290,30 @@ testouterr_cmd_re bash {load source/1.0} $ans_load $ts_load } + +# check argument management +setenv_var MODULES_SOURCE_CACHE 1 +setenv_var TESTSUITE_SOURCE_CACHE arg1 +set ans [list] +lappend ans [list set VAR bar] +lappend ans [list set _LMFILES_ $mp/source/1.0] +lappend ans [list set LOADEDMODULES source/1.0] +testouterr_cmd bash {load source/1.0} $ans {} + +setenv_var TESTSUITE_SOURCE_CACHE bad_arg1 +set line_num [expr {[cmpversion $tclsh_version 8.6] == -1 ? 2 : 38}] +set tserr [escre [msg_load source/1.0 [msg_moderr {wrong # args: should be "source ?-encoding? ?encodingName? fileName"} {source} $mp/source/1.0 $line_num]]] +testouterr_cmd_re bash {load source/1.0} ERR $tserr +set line_num [expr {[cmpversion $tclsh_version 8.6] == -1 ? 2 : 41}] +set tserr [escre [msg_load source/1.0 [msg_moderr {Invalid option '-foo'} {source} $mp/source/1.0 $line_num]]] +setenv_var TESTSUITE_SOURCE_CACHE bad_arg2 +testouterr_cmd_re bash {load source/1.0} ERR $tserr +setenv_var TESTSUITE_SOURCE_CACHE bad_arg3 +set line_num [expr {[cmpversion $tclsh_version 8.6] == -1 ? 2 : 44}] +set tserr [escre [msg_load source/1.0 [msg_moderr {wrong # args: should be "source ?-encoding? ?encodingName? fileName"} {source} $mp/source/1.0 $line_num]]] +testouterr_cmd_re bash {load source/1.0} ERR $tserr + + # cannot test access if cannot change file permission if {!$is_file_perms_editable} { send_user "\tskipping access tests as file permissions cannot be changed\n"