]> Cypherpunks repositories - gostls13.git/commit
reflect: prevent structs with invalid field name
authorPravendra Singh <hackpravj@gmail.com>
Tue, 13 Jun 2017 16:43:07 +0000 (22:13 +0530)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 13 Jun 2017 21:51:17 +0000 (21:51 +0000)
commit538b3a5f37a5316a4ba081fd5a8eb5fb09992ba7
tree9ad09131a1698fbb06e20922af4d22f24723034f
parentf363817f143a7cee0ccdb7833a99ac1e8f210197
reflect: prevent structs with invalid field name

According to the language spec, a struct field name should
be an identifier.

  identifier = letter { letter | unicode_digit } .
  letter = unicode_letter | "_" .

Implements a function 'isValidFieldName(fieldName string) bool'.
To check if the field name is a valid identifier or not.
It will panic if the field name is invalid.

It uses the non-exported function implementation 'isLetter'
from the package 'scanner', used to parse an identifier.

Fixes #20600.

Change-Id: I1db7db1ad88cab5dbea6565be15cc7461cc56c44
Reviewed-on: https://go-review.googlesource.com/45590
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/reflect/all_test.go
src/reflect/type.go