From eee1558dd9300fdb2ee8b96e42e07cbccf3e1ad0 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sun, 17 Dec 2017 16:10:59 +0100 Subject: [PATCH] admin/sync: new error on flags import --- admin/sync/exercice_keys.go | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/admin/sync/exercice_keys.go b/admin/sync/exercice_keys.go index 91da833d..a209783f 100644 --- a/admin/sync/exercice_keys.go +++ b/admin/sync/exercice_keys.go @@ -4,10 +4,20 @@ import ( "fmt" "path" "strings" + "unicode" "srs.epita.fr/fic-server/libfic" ) +func isFullGraphic(s string) bool { + for _, c := range s { + if !unicode.IsGraphic(c) { + return false + } + } + return true +} + func SyncExerciceKeys(i Importer, exercice fic.Exercice) []string { var errs []string @@ -23,16 +33,21 @@ func SyncExerciceKeys(i Importer, exercice fic.Exercice) []string { continue } - var label, rawkey string if len(flag_splt) == 1 { - rawkey = flag_splt[0] - } else { - label = flag_splt[0] - rawkey = flag_splt[1] + errs = append(errs, fmt.Sprintf("%q: error in flags file at line %d: no separator found", path.Base(exercice.Path), nline + 1)) + continue } - if len(label) == 0 { + var label, rawkey string + if len(flag_splt[0]) == 0 { label = "Flag" + } else { + label = flag_splt[0] + } + rawkey = flag_splt[1] + + if !isFullGraphic(rawkey) { + errs = append(errs, fmt.Sprintf("%q: WARNING in flags file at line %d: non-printable characters in flag, is this really expected?", path.Base(exercice.Path), nline + 1)) } if _, err := exercice.AddRawKey(label, rawkey); err != nil { @@ -104,6 +119,11 @@ func SyncExerciceMCQ(i Importer, exercice fic.Exercice) []string { continue } + if len(quest) < 2 { + errs = append(errs, fmt.Sprintf("%q: error in mcq file at line %d: missing label", path.Base(exercice.Path), nline + 1)) + continue + } + if _, err := flag.AddEntry(choice[1:], choice[0] == 49); err != nil { errs = append(errs, fmt.Sprintf("%q: error in mcq file at line %d,%d: %s", path.Base(exercice.Path), nline + 1, cid, err)) continue