Skip to content

Commit c002b43

Browse files
committed
Fix empty query parameters in expand_params method
Previously, there was no distinction between parameters passed to the backend with an empty value. For example, when parsing the query string `?expand`, Rails would include the key but with a nil value in the `params` hash. When this hash was later serialized back into a query string using the `.to_query` method, it erroneously resulted in `?expand=`. This incorrect modification caused the backend to throw a 400 error. This commit resolves the issue by splitting query parameters into two distinct groups of parameters and handling them differently.
1 parent fc622a8 commit c002b43

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/api/app/lib/backend/connection_helper.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,13 @@ def expand_params(params, expand)
114114

115115
expanded_params += params.delete(key).map { |value| value.to_query(key) } if params.key?(key)
116116
end
117-
expanded_params += [params.to_query] unless params.empty?
118-
expanded_params
117+
118+
empty_query_parameters = params.select { |_, v| v.nil? }
119+
expanded_params += [empty_query_parameters.keys.join('&')]
120+
121+
expanded_params += [params.except(*empty_query_parameters.keys).to_query]
122+
123+
expanded_params.compact_blank
119124
end
120125

121126
def calculate_endpoint(endpoint)

0 commit comments

Comments
 (0)