Bug #78139 [Opn]: timezone_open accepts invalid timezone string argument

From: Date: Tue, 11 Jun 2019 06:41:42 +0000
Subject: Bug #78139 [Opn]: timezone_open accepts invalid timezone string argument
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-221211@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78139&edit=1

 ID:                 78139
 Updated by:         requinix@php.net
 Reported by:        baby-luck at earthling dot net
 Summary:            timezone_open accepts invalid timezone string
                     argument
 Status:             Open
 Type:               Bug
 Package:            Date/time related
 Operating System:   Linux
 PHP Version:        7.2.19
 Block user comment: N
 Private report:     N

 New Comment:

"C" and "X" are valid timezones: military notation representing each hourly
division from UTC+12 to UTC-12.

Either
a) this is a doc bug that it takes the first "word" in the string, or
b) this is a code bug and timezone_open should use the whole string


Previous Comments:
------------------------------------------------------------------------
[2019-06-11 06:30:14] baby-luck at earthling dot net

Description:
------------
timezone_open() accepts undocumented/nonsense/partial timezones.
The docs say "One of the supported timezone names or an offset value" but accepts
seemingly nonsense timezones without failure, and timezones found in the first non-whitespace block
in the argument string.

Test script:
---------------
$tz = timezone_open("x UTC");
echo '"x UTC" = '; var_dump($tz);

$tz = timezone_open("c");
echo '"c" = '; var_dump($tz);

$tz = timezone_open("xx UTC");
echo '"xx UTC" = '; var_dump($tz);

$tz = timezone_open("xUTC");
echo '"xUTC" = '; var_dump($tz);

$tz = timezone_open("UTCx");
echo '"UTCx" = '; var_dump($tz);

$tz = timezone_open("UTC xx");
echo '"UTC xx" = '; var_dump($tz);


Expected result:
----------------
"x UTC" = bool(false)
"c" = bool(false)
"xx UTC" = bool(false)
"xUTC" = bool(false)
"UTCx" = bool(false)
"UTC xx" = bool(false)


Actual result:
--------------
"x UTC" = object(DateTimeZone)#127 (2) {
  ["timezone_type"]=>
  int(2)
  ["timezone"]=>
  string(1) "X"
}
"c" = object(DateTimeZone)#128 (2) {
  ["timezone_type"]=>
  int(2)
  ["timezone"]=>
  string(1) "C"
}
"xx UTC" = bool(false)
"xUTC" = bool(false)
"UTCx" = bool(false)
"UTC xx" = object(DateTimeZone)#128 (2) {
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(3) "UTC"
}


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=78139&edit=1


Thread (7 messages)

« previous php.bugs (#221211) next »