Skip to content

Fix error on column names with underscores.#158

Closed
yawboakye wants to merge 1 commit intoJSONAPI-Resources:masterfrom
yawboakye:fix-param-not-allowed-error-on-column-names-with-underscores
Closed

Fix error on column names with underscores.#158
yawboakye wants to merge 1 commit intoJSONAPI-Resources:masterfrom
yawboakye:fix-param-not-allowed-error-on-column-names-with-underscores

Conversation

@yawboakye
Copy link
Copy Markdown
Contributor

The allowed fields are formatted and collected in
formatted_allowed_fields array, which is used during the comparison.
During comparison though, keys from the params[:data] hash are not
formatted before verifying whether they are allowed. Thus keys with
underscores will always fail. This fix makes sure the comparison is done
using the formatted version of the keys.

The allowed fields are formatted and collected in
`formatted_allowed_fields` array, which is used during the comparison.
During comparison though, keys from the `params[:data]` hash are not
formatted before verifying whether they are allowed. Thus keys with
underscores will always fail. This fix makes sure the comparison is done
using the formatted version of the keys.
@lgebhardt
Copy link
Copy Markdown
Contributor

I think I should clean up the logic in verify_permitted_params, since I guessing it's confusing. It's comparing the keys in the request to the formatted version of the allowed keys in the Resource. Therefor it's not necessary to format the key in the request, since it should match one of the formatted resource key.

I'm going to close this PR. If it's still an issue please open a new issue and we can discuss the details.

@lgebhardt lgebhardt closed this Apr 14, 2015
@yawboakye
Copy link
Copy Markdown
Contributor Author

@lgebhardt Is the keys in the request payload expected to be dasherized? Then that's fine. Otherwise, even though the elements of formatted_allowed_fields are ok, the keys in params[:data] may contain underscores during comparison (key in https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/request.rb#L350 has underscores).

@lgebhardt
Copy link
Copy Markdown
Contributor

@yawboakye The json_key_format configuration option controls the format of the keys in the request payload. If it's set to dasherized_key then the keys in the payload are required to be dasherized.

I've added #168 to test this.

@yawboakye
Copy link
Copy Markdown
Contributor Author

@lgebhardt I made the wrong assumptions about the default json_key_format and it's effect on the request payload. Really sorry for bothering you.

@yawboakye yawboakye deleted the fix-param-not-allowed-error-on-column-names-with-underscores branch April 21, 2015 10:29
@lgebhardt
Copy link
Copy Markdown
Contributor

@yawboakye No problem. This made me see I was missing some tests for the formatted keys, so that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants