{"action":"closed","issue":{"url":"https://api.github.com/repos/golang/go/issues/26374","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/26374/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/26374/comments","events_url":"https://api.github.com/repos/golang/go/issues/26374/events","html_url":"https://github.com/golang/go/issues/26374","id":341082341,"node_id":"MDU6SXNzdWUzNDEwODIzNDE=","number":26374,"title":"text/scanner: Float tokens allow trailing 'e' or 'E' and sign (but Go literals don't)","user":{"login":"benhoyt","id":999033,"node_id":"MDQ6VXNlcjk5OTAzMw==","avatar_url":"https://avatars3.githubusercontent.com/u/999033?v=4","gravatar_id":"","url":"https://api.github.com/users/benhoyt","html_url":"https://github.com/benhoyt","followers_url":"https://api.github.com/users/benhoyt/followers","following_url":"https://api.github.com/users/benhoyt/following{/other_user}","gists_url":"https://api.github.com/users/benhoyt/gists{/gist_id}","starred_url":"https://api.github.com/users/benhoyt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benhoyt/subscriptions","organizations_url":"https://api.github.com/users/benhoyt/orgs","repos_url":"https://api.github.com/users/benhoyt/repos","events_url":"https://api.github.com/users/benhoyt/events{/privacy}","received_events_url":"https://api.github.com/users/benhoyt/received_events","type":"User","site_admin":false},"labels":[{"id":373399998,"node_id":"MDU6TGFiZWwzNzMzOTk5OTg=","url":"https://api.github.com/repos/golang/go/labels/NeedsFix","name":"NeedsFix","color":"ededed","default":false}],"state":"closed","locked":false,"assignee":{"login":"griesemer","id":8528975,"node_id":"MDQ6VXNlcjg1Mjg5NzU=","avatar_url":"https://avatars2.githubusercontent.com/u/8528975?v=4","gravatar_id":"","url":"https://api.github.com/users/griesemer","html_url":"https://github.com/griesemer","followers_url":"https://api.github.com/users/griesemer/followers","following_url":"https://api.github.com/users/griesemer/following{/other_user}","gists_url":"https://api.github.com/users/griesemer/gists{/gist_id}","starred_url":"https://api.github.com/users/griesemer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/griesemer/subscriptions","organizations_url":"https://api.github.com/users/griesemer/orgs","repos_url":"https://api.github.com/users/griesemer/repos","events_url":"https://api.github.com/users/griesemer/events{/privacy}","received_events_url":"https://api.github.com/users/griesemer/received_events","type":"User","site_admin":false},"assignees":[{"login":"griesemer","id":8528975,"node_id":"MDQ6VXNlcjg1Mjg5NzU=","avatar_url":"https://avatars2.githubusercontent.com/u/8528975?v=4","gravatar_id":"","url":"https://api.github.com/users/griesemer","html_url":"https://github.com/griesemer","followers_url":"https://api.github.com/users/griesemer/followers","following_url":"https://api.github.com/users/griesemer/following{/other_user}","gists_url":"https://api.github.com/users/griesemer/gists{/gist_id}","starred_url":"https://api.github.com/users/griesemer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/griesemer/subscriptions","organizations_url":"https://api.github.com/users/griesemer/orgs","repos_url":"https://api.github.com/users/griesemer/repos","events_url":"https://api.github.com/users/griesemer/events{/privacy}","received_events_url":"https://api.github.com/users/griesemer/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/65","html_url":"https://github.com/golang/go/milestone/65","labels_url":"https://api.github.com/repos/golang/go/milestones/65/labels","id":3072996,"node_id":"MDk6TWlsZXN0b25lMzA3Mjk5Ng==","number":65,"title":"Go1.12","description":"","creator":{"login":"rsc","id":104030,"node_id":"MDQ6VXNlcjEwNDAzMA==","avatar_url":"https://avatars1.githubusercontent.com/u/104030?v=4","gravatar_id":"","url":"https://api.github.com/users/rsc","html_url":"https://github.com/rsc","followers_url":"https://api.github.com/users/rsc/followers","following_url":"https://api.github.com/users/rsc/following{/other_user}","gists_url":"https://api.github.com/users/rsc/gists{/gist_id}","starred_url":"https://api.github.com/users/rsc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsc/subscriptions","organizations_url":"https://api.github.com/users/rsc/orgs","repos_url":"https://api.github.com/users/rsc/repos","events_url":"https://api.github.com/users/rsc/events{/privacy}","received_events_url":"https://api.github.com/users/rsc/received_events","type":"User","site_admin":false},"open_issues":625,"closed_issues":77,"state":"open","created_at":"2018-01-29T21:17:52Z","updated_at":"2018-08-20T17:04:29Z","due_on":"2019-01-31T08:00:00Z","closed_at":null},"comments":7,"created_at":"2018-07-13T16:27:55Z","updated_at":"2018-08-20T17:04:29Z","closed_at":"2018-08-20T17:04:29Z","author_association":"NONE","body":"The documentation for text/scanner says that it \"recognizes all literals as defined by the Go language specification\". However, it seems to break that and be a little more liberal in that it accepts floating-point literals with a trailing `e` or `E` and no digits. It also allows a trailing `+` or `-` sign after the `e`/`E`. Neither of these are valid Go floating point literals (nor as input to ParseFloat, which seems to match the [Go literal spec](https://golang.org/ref/spec#Floating-point_literals) here).\r\n\r\nHere is a Playground link to a small program that reproduces the issue: https://play.golang.org/p/leS1zsI4Rfz\r\n\r\nIn short, scanning the string `\"1.5e 1.5E 1e 1E 1e+ 1e- 1.0 1 1.5z\"` gives the following sequence of tokens (third value on each line is whether it's valid according to Go/ParseFloat or not):\r\n\r\n```\r\nFloat \"1.5e\" false\r\nFloat \"1.5E\" false\r\nFloat \"1e\" false\r\nFloat \"1E\" false\r\nFloat \"1e+\" false\r\nFloat \"1e-\" false\r\nFloat \"1.0\" true\r\nInt \"1\" true\r\nFloat \"1.5\" true\r\nIdent \"z\" false\r\n```\r\n\r\nHowever, what I'd expect according to the text/scanner docs is for the trailing `e`'s and signs to be not included in the float, but parsed as subsequent tokens, like so:\r\n\r\n```\r\nFloat \"1.5\" true\r\nIdent \"e\" false\r\nFloat \"1.5\" true\r\nIdent \"E\" false\r\nInt \"1\" true\r\nIdent \"e\" false\r\nInt \"1\" true\r\nIdent \"E\" false\r\nInt \"1\" true\r\nIdent \"e\" false\r\n\"+\" \"+\" false\r\nInt \"1\" true\r\nIdent \"e\" false\r\n\"-\" \"-\" false\r\nFloat \"1.0\" true\r\nInt \"1\" true\r\nFloat \"1.5\" true\r\nIdent \"z\" false\r\n```\r\n\r\nHere's the relevant [scanner.go source code](https://golang.org/src/text/scanner/scanner.go#L367). scanExponent uses scanMantissa, which allows 0 or more digits instead of 1 or more digits (for this case).\r\n\r\nI ran into this issue when using text/scanner and then passing the TokenText() return value for Float tokens to ParseFloat, and getting an unexpected error on strings like `1.5e`.\r\n\r\nGo version and OS/arch: `go1.10 darwin/amd64`. Though from looking at the code it's not arch- or OS-specific. Yes, the issue reproduces with the latest release.\r\n\r\nIf folks (@griesemer?) agree that this is a bug, I'd be interested in contributing a fix. However, if it's decided that users may be depending on this behavior (seem unlikely as this apparently hasn't been reported yet -- I searched for issues) and it's too late to change it, then we'll want a documentation fix."}}
{"actor":{"display_login":"gopherbot"}}