Commit 5d2af360 authored by COOKE TARA's avatar COOKE TARA
Browse files

determine accurate string length on db name update

parent 4fba809c
......@@ -29,12 +29,13 @@ import (
"strconv"
"strings"
"time"
"unicode/utf8"
"github.com/jmoiron/sqlx"
db "gitlab.huma-num.fr/arkeogis/arkeogis-server/db"
"gitlab.huma-num.fr/arkeogis/arkeogis-server/geo"
"gitlab.huma-num.fr/arkeogis/arkeogis-server/model"
"gitlab.huma-num.fr/arkeogis/arkeogis-server/translate"
"github.com/jmoiron/sqlx"
)
// UserChoices stores user preferences for the parsing process
......@@ -288,7 +289,7 @@ func (di *DatabaseImport) ProcessDatabaseName(name string) error {
di.Database.Name = name
// Check database name length
if len(name) > 75 {
if utf8.RuneCountInString(name) > 75 {
di.AddError("", "IMPORT.FORM_DATABASE_NAME.T_CHECK_TOO_LONG", "DATABASE_NAME")
return errors.New("Database name too long")
}
......
......@@ -7,6 +7,7 @@ import (
"regexp"
"strconv"
"strings"
"unicode/utf8"
)
type FieldError struct {
......@@ -297,7 +298,7 @@ func sanitizeFieldMin(field reflect.StructField, tag Tag, value reflect.Value, p
}
case reflect.String:
min, _ := strconv.Atoi(tag.Value)
if len(value.String()) < min {
if utf8.RuneCountInString(value.String()) < min {
setFieldError(field, tag, value, path, fieldname, errors)
return true
}
......@@ -329,7 +330,7 @@ func sanitizeFieldMax(field reflect.StructField, tag Tag, value reflect.Value, p
}
case reflect.String:
max, _ := strconv.Atoi(tag.Value)
if len(value.String()) > max {
if utf8.RuneCountInString(value.String()) > max {
setFieldError(field, tag, value, path, fieldname, errors)
return true
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment