Any and scalar: strings like "Nan", "T", "007" stop being strings

Aperta
#14 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go
Ambito
backend

Direzione di ricerca

Start by reading GetAnyConverter and GetScalarConverter in tt.go, then the parsing functions named in converter.go. Check the existing tests for these converters and run them to see how the current behavior is covered. Done means the listed ambiguous values stay strings for any and scalar, explicitly typed fields retain their permissive parsing, and the behavior change is documented; clarify whether a factory option is needed.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Reproduction snippets assume:

fac := tupleconv.MakeStringToTTConvFactory()

Where: GetAnyConverter (tt.go:174), GetScalarConverter (tt.go:188), StringToFloatConverter (converter.go:146), StringToBoolConverter (converter.go:98).

any and scalar try number, decimal, boolean... before string, and the underlying strconv functions are very permissive:

  • ParseFloat accepts nan, inf, infinity in any case.
  • ParseBool accepts t, T, f, F, 1, 0, TRUE, True...
  • ParseUint drops leading zeros, ParseInt accepts a leading +.

So names, codes and phone numbers are silently turned into other types.

Reproduction:

for _, s := range []string{"Nan", "inf", "T", "f", "007", "+79991234567"} {
	v, err := fac.GetScalarConverter().Convert(s)
	fmt.Printf("%q -> %T(%v) %v\n", s, v, v, err)
}
"Nan" -> float64(NaN) <nil>
"inf" -> float64(+Inf) <nil>
"T" -> bool(true) <nil>
"f" -> bool(false) <nil>
"007" -> uint64(7) <nil>
"+79991234567" -> int64(79991234567) <nil>

GetAnyConverter gives the same results.

Expected: for any/scalar, only unambiguous literals change type; the values above stay strings.

Suggested fix: use a stricter grammar for any/scalar: no nan/inf, no leading +, no leading zeros except 0 itself, and only true/false for booleans. Explicitly typed fields (double, boolean...) may keep the permissive parsing. This changes behavior, so it needs a CHANGELOG entry and possibly an option on the factory.

Lingua principale
Go
Stelle
1
Fork
0
Merge medio
1h 43m
PR unite (30g)
2

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tarantool/go-tupleconv

Tutte le issue di tarantool/go-tupleconv

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.