mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-03-21 22:49:42 +02:00
normalized negative multipart/form-data numeric inferred value check
This commit is contained in:
parent
274d499279
commit
cb0335c2b6
@ -325,7 +325,8 @@ func inferValue(raw string) any {
|
|||||||
// try to convert to number
|
// try to convert to number
|
||||||
//
|
//
|
||||||
// note: expects the provided raw string to match exactly with the minimal string representation of the parsed float
|
// note: expects the provided raw string to match exactly with the minimal string representation of the parsed float
|
||||||
if raw[0] == '-' || (raw[0] >= '0' && raw[0] <= '9') && inferNumberCharsRegex.Match([]byte(raw)) {
|
if (raw[0] == '-' || (raw[0] >= '0' && raw[0] <= '9')) &&
|
||||||
|
inferNumberCharsRegex.Match([]byte(raw)) {
|
||||||
v, err := strconv.ParseFloat(raw, 64)
|
v, err := strconv.ParseFloat(raw, 64)
|
||||||
if err == nil && strconv.FormatFloat(v, 'f', -1, 64) == raw {
|
if err == nil && strconv.FormatFloat(v, 'f', -1, 64) == raw {
|
||||||
return v
|
return v
|
||||||
|
@ -31,6 +31,7 @@ func TestUnmarshalRequestData(t *testing.T) {
|
|||||||
"000001",
|
"000001",
|
||||||
"-000001",
|
"-000001",
|
||||||
"1.6E-35",
|
"1.6E-35",
|
||||||
|
"-1.6E-35",
|
||||||
"10e100",
|
"10e100",
|
||||||
"1_000_000",
|
"1_000_000",
|
||||||
"1.000.000",
|
"1.000.000",
|
||||||
@ -328,7 +329,7 @@ func TestUnmarshalRequestData(t *testing.T) {
|
|||||||
name: "*map[string]any",
|
name: "*map[string]any",
|
||||||
data: mapData,
|
data: mapData,
|
||||||
dst: pointer(map[string]any{}),
|
dst: pointer(map[string]any{}),
|
||||||
result: `{"bool1":true,"bool2":[true,false],"json_a":null,"json_b":123,"json_c":[1,2,3],"mixed":[true,123,"test"],"number1":1,"number2":[2,3],"number3":[2.1,-3.4],"number4":[0,-0,0.0001],"string0":"","string1":"a","string2":["b","c"],"string3":["0.0","-0.0","000.1","000001","-000001","1.6E-35","10e100","1_000_000","1.000.000"," 123 ","0b1","0xFF","1234A","Infinity","-Infinity","undefined","null"]}`,
|
result: `{"bool1":true,"bool2":[true,false],"json_a":null,"json_b":123,"json_c":[1,2,3],"mixed":[true,123,"test"],"number1":1,"number2":[2,3],"number3":[2.1,-3.4],"number4":[0,-0,0.0001],"string0":"","string1":"a","string2":["b","c"],"string3":["0.0","-0.0","000.1","000001","-000001","1.6E-35","-1.6E-35","10e100","1_000_000","1.000.000"," 123 ","0b1","0xFF","1234A","Infinity","-Infinity","undefined","null"]}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "valid pointer struct (all fields)",
|
name: "valid pointer struct (all fields)",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user