From a53641e773730ba171df2602c8d199968d6e6447 Mon Sep 17 00:00:00 2001 From: MrArmonius Date: Mon, 26 Jul 2021 15:36:45 +0200 Subject: Correct the function GenerateName MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The problem was the encode in `name += string(alphabet[])` It takes only 1 byte but the characters like 'è','@' are encoding on several bytes (1 to 4 bytes). The better solution was to create a slice of string, like this we don't have problem about take only one byte instead of 2,3 or 4 bytes. --- test/handler.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/handler.go b/test/handler.go index 0e7a95b..43fad77 100644 --- a/test/handler.go +++ b/test/handler.go @@ -32,7 +32,9 @@ func PrintError(LDAPError error) { //Generate an unique name, which store in all_names func (inst *instance) GenerateName() (name string) { - alphabet := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + alphabet := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", + "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", + "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "é", "è", "ê", "ë", "à", "@", "â", "ä", "û", "ü", "ù", "$", "£", "%", "ø", "€"} length := R.Intn(maxlength_generateName) + minlength_generateName //Check if this name not exist already @@ -41,7 +43,7 @@ func (inst *instance) GenerateName() (name string) { for only_one := true; only_one; _, only_one = allNames.cn[name] { //Create the name for i := 0; i < length; i++ { - name += string(alphabet[R.Intn(len(alphabet))]) + name += alphabet[R.Intn(len(alphabet))] } } -- cgit v1.2.3