• Pravendra Singh's avatar
    reflect: prevent structs with invalid field name · 538b3a5f
    Pravendra Singh authored
    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/45590Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    538b3a5f
all_test.go 155 KB