MCPcopy
hub / github.com/ory/hydra / decodeURLValues

Function decodeURLValues

oryx/decoderx/http.go:393–535  ·  view source on GitHub ↗
(values url.Values, paths []jsonschemax.Path, o *httpDecoderOptions)

Source from the content-addressed store, hash-verified

391}
392
393func decodeURLValues(values url.Values, paths []jsonschemax.Path, o *httpDecoderOptions) (json.RawMessage, error) {
394 raw := json.RawMessage(`{}`)
395 for key := range values {
396 for _, path := range paths {
397 if key == path.Name {
398 var err error
399 switch path.Type.(type) {
400 case []string:
401 raw, err = sjson.SetBytes(raw, path.Name, values[key])
402 case []float64:
403 for k, v := range values[key] {
404 var f float64
405 if f, err = strconv.ParseFloat(v, 64); err != nil {
406 switch o.handleParseErrors {
407 case ParseErrorIgnoreConversionErrors:
408 raw, err = sjson.SetBytes(raw, path.Name+"."+strconv.Itoa(k), v)
409 case ParseErrorUseEmptyValueOnConversionErrors:
410 raw, err = sjson.SetBytes(raw, path.Name+"."+strconv.Itoa(k), f)
411 case ParseErrorReturnOnConversionErrors:
412 return nil, errors.WithStack(herodot.ErrBadRequest.WithReasonf("Expected value to be a number.").
413 WithDetail("parse_error", err.Error()).
414 WithDetail("name", key).
415 WithDetailf("index", "%d", k).
416 WithDetail("value", v))
417 }
418 } else {
419 raw, err = sjson.SetBytes(raw, path.Name+"."+strconv.Itoa(k), f)
420 }
421 }
422 case []bool:
423 for k, v := range values[key] {
424 var b bool
425 if b, err = strconv.ParseBool(v); err != nil {
426 switch o.handleParseErrors {
427 case ParseErrorIgnoreConversionErrors:
428 raw, err = sjson.SetBytes(raw, path.Name+"."+strconv.Itoa(k), v)
429 case ParseErrorUseEmptyValueOnConversionErrors:
430 raw, err = sjson.SetBytes(raw, path.Name+"."+strconv.Itoa(k), b)
431 case ParseErrorReturnOnConversionErrors:
432 return nil, errors.WithStack(herodot.ErrBadRequest.WithReasonf("Expected value to be a boolean.").
433 WithDetail("parse_error", err.Error()).
434 WithDetail("name", key).
435 WithDetailf("index", "%d", k).
436 WithDetail("value", v))
437 }
438 } else {
439 raw, err = sjson.SetBytes(raw, path.Name+"."+strconv.Itoa(k), b)
440 }
441 }
442 case []interface{}:
443 raw, err = sjson.SetBytes(raw, path.Name, values[key])
444 case bool:
445 v := values[key][len(values[key])-1]
446 if len(v) == 0 {
447 if !path.Required {
448 continue
449 }
450 v = "false"

Callers 2

decodeJSONFormFunction · 0.85
decodeFormFunction · 0.85

Calls 2

GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected