Skip to content

Commit

Permalink
closes gh-24 (back-ported from regression fix for tcl-core [2c237beff…
Browse files Browse the repository at this point in the history
…bace823]):

  - usage of time zones `Etc/GMT±n` is allowed now (were impossible previously due to incorrect prevention of path escape for the tzdata directory);
  - test coverage (test clock-59.2)
  • Loading branch information
sebres committed Oct 29, 2024
1 parent a2ea943 commit 723c71d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/clock.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ proc ::tcl::clock::LoadTimeZoneFile { fileName } {
# is security sensitive. Make sure that the path name cannot escape the
# given directory.

if { ![regexp {^[[.-.][:alpha:]_]+(?:/[[.-.][:alpha:]_]+)*$} $fileName] } {
if { [regexp {^[/\\]|^[a-zA-Z]+:|(?:^|[/\\])\.\.} $fileName] } {
return -code error \
-errorcode [list CLOCK badTimeZone $:fileName] \
"time zone \":$fileName\" not valid"
Expand Down Expand Up @@ -1262,7 +1262,7 @@ proc ::tcl::clock::LoadZoneinfoFile { fileName } {
# is security sensitive. Make sure that the path name cannot escape the
# given directory.

if { ![regexp {^[[.-.][:alpha:]_]+(?:/[[.-.][:alpha:]_]+)*$} $fileName] } {
if { [regexp {^[/\\]|^[a-zA-Z]+:|(?:^|[/\\])\.\.} $fileName] } {
return -code error \
-errorcode [list CLOCK badTimeZone $:fileName] \
"time zone \":$fileName\" not valid"
Expand Down
17 changes: 17 additions & 0 deletions tests/clock.test
Original file line number Diff line number Diff line change
Expand Up @@ -38201,6 +38201,23 @@ test clock-59.1 {military time zones} {
join $trouble \n
} {}

test clock-59.2 {correct time zone names, format and scan back, bug and regression [2c237beffbace823]} {
set result {}
foreach {base tz} {
1700000000 "Etc/GMT-2"
1700000000 "Etc/GMT+2"
1301184000 "Europe/Kaliningrad"
152632800 "Pacific/Chatham"
-765317964 "America/Paramaribo"
-2337928528 "Australia/Eucla"
} {
set v [clock format $base -timezone Etc/GMT-2 -format "%Y-%m-%d %H:%M:%S %Z"]
lappend result [expr {[set t [clock scan $v -format "%Y-%m-%d %H:%M:%S %Z"]] == $base ? 1 : "0 ($t != $base for $v)"}]
lappend result [expr {[set t [clock scan $v]] == $base ? 1 : "0 ($t != $base for $v)"}]
}
set result
} [lrepeat 12 1]

# case-insensitive matching of weekday and month names [Bug 1781282]

test clock-60.1 {case insensitive weekday names} {
Expand Down

0 comments on commit 723c71d

Please sign in to comment.