(query string, defaultKey func(term string, values url.Values) error)
| 642 | } |
| 643 | |
| 644 | func searchTerms(query string, defaultKey func(term string, values url.Values) error) (url.Values, []codersdk.ValidationError) { |
| 645 | searchValues := make(url.Values) |
| 646 | |
| 647 | // Because we do this in 2 passes, we want to maintain quotes on the first |
| 648 | // pass. Further splitting occurs on the second pass and quotes will be |
| 649 | // dropped. |
| 650 | tokens := splitQueryParameterByDelimiter(query, ' ', true) |
| 651 | elements := processTokens(tokens) |
| 652 | for _, element := range elements { |
| 653 | if strings.HasPrefix(element, ":") || strings.HasSuffix(element, ":") { |
| 654 | return nil, []codersdk.ValidationError{ |
| 655 | { |
| 656 | Field: "q", |
| 657 | Detail: fmt.Sprintf("Query element %q cannot start or end with ':'", element), |
| 658 | }, |
| 659 | } |
| 660 | } |
| 661 | parts := splitQueryParameterByDelimiter(element, ':', false) |
| 662 | switch len(parts) { |
| 663 | case 1: |
| 664 | // No key:value pair. Use default behavior. |
| 665 | err := defaultKey(element, searchValues) |
| 666 | if err != nil { |
| 667 | return nil, []codersdk.ValidationError{ |
| 668 | {Field: "q", Detail: err.Error()}, |
| 669 | } |
| 670 | } |
| 671 | case 2: |
| 672 | searchValues.Add(strings.ToLower(parts[0]), parts[1]) |
| 673 | default: |
| 674 | return nil, []codersdk.ValidationError{ |
| 675 | { |
| 676 | Field: "q", |
| 677 | Detail: fmt.Sprintf("Query element %q can only contain 1 ':'", element), |
| 678 | }, |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | return searchValues, nil |
| 684 | } |
| 685 | |
| 686 | func parseOrganization(ctx context.Context, db database.Store, parser *httpapi.QueryParamParser, vals url.Values, queryParam string) uuid.UUID { |
| 687 | return httpapi.ParseCustom(parser, vals, uuid.Nil, queryParam, func(v string) (uuid.UUID, error) { |
no test coverage detected