Skip to content

Commit 5fdf97a

Browse files
committed
Fix empty query parameters in expand_parameters method
Before, there was no distinction between empty parameters passed to the backend. For example, for this query string: `?expand` The query parameter string was parsed into `params` (by Rails), and later on, translated into a query parameter string with the method `.to_query`. This lead to passing empty query parameters adding an `=` sign in the end. For example: `?expand=`. That make the backend throw a 400 error with a boolean value not recognized. This commit, split the query parameters in empty and non-empty, solving this issue.
1 parent fc622a8 commit 5fdf97a

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)