time: bugs in parsing time string with GMT as time zone. #40472
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Go Playground,
Go 1.14.6
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/UJyx6fMkbJW
What did you expect to see?
All tests passed without error.
What did you see instead?
The GMT ones except "GMT+0800" failed with
cannot parse "" as "-0700"
orcannot parse "" as "-07"
.Details:
When parsing time zones, the
Parse
function callsparseTimeZone
, which makes a special case for parsing GMT time zone (which I don't understand why), calling and returning results fromparseGMT
, as bytes to consume byParse
function.go/src/time/format.go
Lines 1047 to 1059 in 85afa2e
go/src/time/format.go
Lines 1209 to 1212 in 85afa2e
The
parseGMT
function tries to return more than 3 bytes, which is the"GMT"
string, as in other time zone format. You can see in the playground link, that it returns 8 bytes for"GMT+0000"
, and leaving nothing to match with "-0700" in the layout string.go/src/time/format.go
Lines 1247 to 1280 in 85afa2e
Interestingly (and confusingly) it does so by checking whether the following string is a signed integer which is in range from
-23
to+23
, excluding leading zeroes - but it considers"+0800"
as800
, which makes it invalid, soparseGMT
returns 3, which makesParse
functions without an error.However, all other values showed in the tests (
"+0000"
, "+08") are considered valid, and making theParse
function consumes too much.The text was updated successfully, but these errors were encountered: