(b []byte, p unsafe.Pointer, t reflect.Type, decode decodeFunc)
| 325 | } |
| 326 | |
| 327 | func (d decoder) decodeFromStringToInt(b []byte, p unsafe.Pointer, t reflect.Type, decode decodeFunc) ([]byte, error) { |
| 328 | if hasNullPrefix(b) { |
| 329 | return decode(d, b, p) |
| 330 | } |
| 331 | |
| 332 | if len(b) > 0 && b[0] != '"' { |
| 333 | v, r, k, err := d.parseNumber(b) |
| 334 | if err == nil { |
| 335 | // The encoding/json package will return a *json.UnmarshalTypeError if |
| 336 | // the input was a floating point number representation, even tho a |
| 337 | // string is expected here. |
| 338 | if k == Float { |
| 339 | _, err := strconv.ParseFloat(*(*string)(unsafe.Pointer(&v)), 64) |
| 340 | if err != nil { |
| 341 | return r, unmarshalTypeError(v, t) |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | return r, fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal unquoted value into int") |
| 346 | } |
| 347 | |
| 348 | if len(b) > 1 && b[0] == '"' && b[1] == '"' { |
| 349 | return b, fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal \"\" into int") |
| 350 | } |
| 351 | |
| 352 | v, b, _, err := d.parseStringUnquote(b, nil) |
| 353 | if err != nil { |
| 354 | return d.inputError(v, t) |
| 355 | } |
| 356 | |
| 357 | if hasLeadingZeroes(v) { |
| 358 | // In this context the encoding/json package accepts leading zeroes because |
| 359 | // it is not constrained by the JSON syntax, remove them so the parsing |
| 360 | // functions don't return syntax errors. |
| 361 | u := make([]byte, 0, len(v)) |
| 362 | i := 0 |
| 363 | |
| 364 | if i < len(v) && v[i] == '-' || v[i] == '+' { |
| 365 | u = append(u, v[i]) |
| 366 | i++ |
| 367 | } |
| 368 | |
| 369 | for (i+1) < len(v) && v[i] == '0' && '0' <= v[i+1] && v[i+1] <= '9' { |
| 370 | i++ |
| 371 | } |
| 372 | |
| 373 | v = append(u, v[i:]...) |
| 374 | } |
| 375 | |
| 376 | if r, err := decode(d, v, p); err != nil { |
| 377 | if _, isSyntaxError := err.(*SyntaxError); isSyntaxError { |
| 378 | if hasPrefix(v, "-") { |
| 379 | // The standard library interprets sequences of '-' characters |
| 380 | // as numbers but still returns type errors in this case... |
| 381 | return b, unmarshalTypeError(v, t) |
| 382 | } |
| 383 | return b, fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into int", prefix(v)) |
| 384 | } |
no test coverage detected