diff --git a/docs/docs/development/grpc-gateway_v2_migration_guide.md b/docs/docs/development/grpc-gateway_v2_migration_guide.md index 9fb10dd87e5..fe3b131e983 100644 --- a/docs/docs/development/grpc-gateway_v2_migration_guide.md +++ b/docs/docs/development/grpc-gateway_v2_migration_guide.md @@ -162,3 +162,7 @@ There is no workaround for this, as we considered it a correct interpretation of ## Error handling configuration has been overhauled `runtime.HTTPError`, `runtime.OtherErrorHandler`, `runtime.GlobalHTTPErrorHandler`, `runtime.WithProtoErrorHandler` are all gone. Error handling is rewritten around the use of gRPCs Status types. If you wish to configure how the gateway handles errors, please use `runtime.WithErrorHandler` and `runtime.WithStreamErrorHandler`. To handle routing errors (similar to the removed `runtime.OtherErrorHandler`) please use `runtime.WithRoutingErrorHandler`. + +## Default query parameter parsing behaviour change + +The default behaviour for query parameter parsing has changed to return an `InvalidArgument` (`400 Bad Request`) error when more than one of the same matching query parameters is parsed. Previously, it would log but not return an error, using the first query parameter that matched and ignoring any others. See [the original issue](https://github.com/grpc-ecosystem/grpc-gateway/issues/2632) for more information. \ No newline at end of file diff --git a/runtime/query.go b/runtime/query.go index 190e9c4b3ec..c35f7dc69cb 100644 --- a/runtime/query.go +++ b/runtime/query.go @@ -24,7 +24,7 @@ import ( var valuesKeyRegexp = regexp.MustCompile(`^(.*)\[(.*)\]$`) -var currentQueryParser QueryParameterParser = &defaultQueryParser{} +var currentQueryParser QueryParameterParser = &DefaultQueryParser{} // QueryParameterParser defines interface for all query parameter parsers type QueryParameterParser interface { @@ -37,11 +37,15 @@ func PopulateQueryParameters(msg proto.Message, values url.Values, filter *utili return currentQueryParser.Parse(msg, values, filter) } -type defaultQueryParser struct{} +// DefaultQueryParser is a QueryParameterParser which implements the default +// query parameters parsing behavior. +// +// See https://github.com/grpc-ecosystem/grpc-gateway/issues/2632 for more context. +type DefaultQueryParser struct{} // Parse populates "values" into "msg". // A value is ignored if its key starts with one of the elements in "filter". -func (*defaultQueryParser) Parse(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error { +func (*DefaultQueryParser) Parse(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error { for key, values := range values { match := valuesKeyRegexp.FindStringSubmatch(key) if len(match) == 3 {