@@ -547,6 +547,35 @@ func TestStringToTimeDurationHookFunc(t *testing.T) {
547
547
suite .Run (t )
548
548
}
549
549
550
+ func TestStringToTimeLocationHookFunc (t * testing.T ) {
551
+ newYork , _ := time .LoadLocation ("America/New_York" )
552
+ london , _ := time .LoadLocation ("Europe/London" )
553
+ tehran , _ := time .LoadLocation ("Asia/Tehran" )
554
+ shanghai , _ := time .LoadLocation ("Asia/Shanghai" )
555
+
556
+ suite := decodeHookTestSuite [string , * time.Location ]{
557
+ fn : StringToTimeLocationHookFunc (),
558
+ ok : []decodeHookTestCase [string , * time.Location ]{
559
+ {"UTC" , time .UTC },
560
+ {"Local" , time .Local },
561
+ {"America/New_York" , newYork },
562
+ {"Europe/London" , london },
563
+ {"Asia/Tehran" , tehran },
564
+ {"Asia/Shanghai" , shanghai },
565
+ },
566
+ fail : []decodeHookFailureTestCase [string , * time.Location ]{
567
+ {"UTC2" }, // Non-existent
568
+ {"5s" }, // Duration-like, not a zone
569
+ {"Europe\\ London" }, // Invalid path separator
570
+ {"../etc/passwd" }, // Unsafe path
571
+ {"/etc/zoneinfo" }, // Absolute path (rejected by stdlib)
572
+ {"Asia\\ Tehran" }, // Invalid Windows-style path
573
+ },
574
+ }
575
+
576
+ suite .Run (t )
577
+ }
578
+
550
579
func TestStringToURLHookFunc (t * testing.T ) {
551
580
httpURL , _ := url .Parse ("http://example.com" )
552
581
httpsURL , _ := url .Parse ("https://example.com" )
0 commit comments