From 147db702686b2d11c1a4f388301b131834e2b098 Mon Sep 17 00:00:00 2001 From: Max D Date: Fri, 13 Sep 2024 17:35:55 +0700 Subject: [PATCH] count runes in description fixes utf8 characters that are wider than 1 byte --- formatter/errors.go | 4 ++-- formatter/processor.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/formatter/errors.go b/formatter/errors.go index c973ce9..2f49db0 100644 --- a/formatter/errors.go +++ b/formatter/errors.go @@ -28,8 +28,8 @@ func (e ridlErrors) getLenghts() (codeLen, nameLen, descLen, httpLen int) { nameLen = len(err.name) } - if len(err.description) > descLen { - descLen = len(err.description) + if len([]rune(err.description)) > descLen { + descLen = len([]rune(err.description)) } if len(fmt.Sprintf("%d", err.httpCode)) > httpLen { diff --git a/formatter/processor.go b/formatter/processor.go index c1b5181..f1651e0 100644 --- a/formatter/processor.go +++ b/formatter/processor.go @@ -292,7 +292,7 @@ func (f *form) errorsPrint() string { nameLen, err.name, err.description, - strings.Repeat(" ", descLen-len(err.description)), + strings.Repeat(" ", descLen-len([]rune(err.description))), httpLen, err.httpCode, )