Trim flags to avoid mistakes due to empty lines or espaces...

This commit is contained in:
nemunaire 2021-12-07 16:33:30 +01:00
commit 0cc72712a4
7 changed files with 24 additions and 14 deletions

View file

@ -404,6 +404,7 @@ type uploadedFlag struct {
Placeholder string
IgnoreCase bool
Multiline bool
NoTrim bool
ValidatorRe *string `json:"validator_regexp"`
Flag string
Value []byte
@ -425,7 +426,7 @@ func createExerciceFlag(exercice *fic.Exercice, body []byte) (interface{}, error
vre = uk.ValidatorRe
}
return exercice.AddRawFlagKey(uk.Label, uk.Type, uk.Placeholder, uk.IgnoreCase, uk.Multiline, vre, []byte(uk.Flag), uk.ChoicesCost)
return exercice.AddRawFlagKey(uk.Label, uk.Type, uk.Placeholder, uk.IgnoreCase, uk.NoTrim, uk.Multiline, vre, []byte(uk.Flag), uk.ChoicesCost)
}
func showExerciceFlag(flag *fic.FlagKey, _ *fic.Exercice, body []byte) (interface{}, error) {

View file

@ -38,6 +38,7 @@ type ExerciceFlag struct {
ShowLines bool `toml:",omitempty"`
Ordered bool `toml:",omitempty"`
CaseSensitive bool `toml:",omitempty"`
NoTrim bool `toml:",omitempty"`
ValidatorRe string `toml:"validator_regexp,omitempty"`
Placeholder string `toml:",omitempty"`
Help string `toml:",omitempty"`

View file

@ -124,7 +124,7 @@ func buildKeyFlag(exercice *fic.Exercice, flag ExerciceFlag, flagline int, defau
errs = append(errs, fmt.Sprintf("%q: WARNING flag #%d: non-printable characters in flag, is this really expected?", path.Base(exercice.Path), flagline))
}
hashedFlag, err := fic.ComputeHashedFlag([]byte(raw), !flag.CaseSensitive, validatorRegexp(flag.ValidatorRe))
hashedFlag, err := fic.ComputeHashedFlag([]byte(raw), !flag.CaseSensitive, flag.NoTrim, validatorRegexp(flag.ValidatorRe))
if err != nil {
errs = append(errs, fmt.Sprintf("%q: flag #%d: %s", path.Base(exercice.Path), flagline, err.Error()))
return