mwitkow/go-proto-validators

Support for multibyte strings

tomtwinkle opened this issue · 0 comments

len(string) does not count by characters but by bytes, so if a multibyte string is specified for validation, it cannot be validated by characters.
In order to accurately determine the number of characters, len([]rune(string)) should be used.

p.P(`if !( len(`, variableName, `) < `, fv.LengthLt, `) {`)

v0.3.2 generated

	if !(len(this.Keyword) < 1000) {

I think this is a good way to fix it.

	if !(len([]rune(this.Keyword)) < 1000) {