Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI - don't coerce JSON input to an Object #5271

Merged
merged 2 commits into from
Sep 5, 2018
Merged

Conversation

meirish
Copy link
Contributor

@meirish meirish commented Sep 4, 2018

Previously, we would Object.keys and then loop over the items, assuming the input was an object. Turns out that didn't work so well.

Now, if there is input, and it's not an object, we show an error and disable submission of the form.

The current state with JSON linting errors:
screen shot 2018-09-04 at 4 13 32 pm

Additionally, we now will show this if the input is valid JSON, but not an object (you can't see the whole editor here, but the top level is an array, not an object):
screen shot 2018-09-04 at 4 13 53 pm

Fixes #5153

@meirish meirish requested review from a team September 4, 2018 21:24
export default Ember.ArrayProxy.extend({
fromJSON(json) {
const contents = Object.keys(json || []).map(key => {
if (json && typeOf(json) !== 'object') {
throw new Error('Vault expects data to be formatted as an JSON object.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we explain more than this? I'm afraid they're going to alter it enough so it gets accepted and then run into the same issue now where the keys are array indexes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking this is already the advanced mode so there would be some idea of what they're doing. The index thing was happening because we were using Object.keys on an array, but now we short circuit that, so it would take quite a bit of fiddling to get back there.

What sort of extra explanation were you thinking? Maybe: "The input is valid JSON, but Vault requires the top-level structure to be a JSON Object and currently it is not." Or something like that?

@meirish meirish added this to the 0.11.1 milestone Sep 5, 2018
@meirish
Copy link
Contributor Author

meirish commented Sep 5, 2018

Going to merge to get in for the release - we can still tweak the error message

@meirish meirish merged commit 1137763 into master Sep 5, 2018
@meirish meirish deleted the ui-no-format-json branch September 5, 2018 16:07
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