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

Fixes #2653. Encode details as JSON before filling input #2658

Merged
merged 2 commits into from
Oct 19, 2018
Merged

Conversation

miketaylr
Copy link
Member

This is a bit voodoo magic here. I don't actually know where the details POST param gets added as the hidden input value, before this patch.

It seems like a default Flask / wtform behavior?

Either way, before this patch the hidden input is getting populated with a unicode string that kinda looks like JSON, but is not:

With this patch, we end up with encoded JSON:

screen shot 2018-10-16 at 4 23 23 pm

webcompat/webcompat-tests#1704 is a test bug I filed from my branch.

r? @karlcow

There's follow up work to make it prettier, but I'll file a new bug for that.

@karlcow
Copy link
Member

karlcow commented Oct 17, 2018

Thanks I will review this tomorrow.

Copy link
Member

@karlcow karlcow left a comment

Choose a reason for hiding this comment

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

@miketaylr dirty things indeed.
Could we make sure to leave a comment to explain why we need the dumps there?
And maybe open a new issue on processing/formatting these server side before pushing them to github.

What do you think about the textarea thing? Would it even solve something?

@@ -103,6 +103,7 @@ def get_form(form_data):
ua_header = form_data['user_agent']
# Populate the form
bug_form.browser.data = get_browser(ua_header)
bug_form.details.data = json.dumps(form_data.get('details'))

This comment was marked as abuse.

This comment was marked as abuse.

@karlcow
Copy link
Member

karlcow commented Oct 18, 2018

@miketaylr there is a bizarre thing in your screenshot
screen shot 2018-10-16 at 4 23 23 pm

The input shows double quotes inside double quotes is it really what happens?

This kind of issues are difficult to test without the right client. :)

@miketaylr
Copy link
Member Author

The input shows double quotes inside double quotes is it really what happens?

It's possible this is just DevTools not displaying the escaped quotes.

I ran a little test to be sure:

screen shot 2018-10-17 at 10 00 09 pm

@miketaylr
Copy link
Member Author

Could we make sure to leave a comment to explain why we need the dumps there?

Yeah, this needs a big long comment. :) Will do.

@miketaylr
Copy link
Member Author

Have some local stuff with this approach:

screen shot 2018-10-18 at 5 14 58 pm

I don't love it, but it's better than the current mess. We can make it better in #2659. Hoping to get patches/tests cleaned up for review after the kids go to bed tonight.

@karlcow
Copy link
Member

karlcow commented Oct 18, 2018

let me try something:

{"json": "on one line", "what": "github does", "with them": "no idea"}

@karlcow
Copy link
Member

karlcow commented Oct 18, 2018

ah no specific formatting.

@karlcow
Copy link
Member

karlcow commented Oct 18, 2018

@miketaylr what about doing this before dumping in the textarea

things_for_textarea = json.dumps(details_dict, indent=2)

This changes the way we build details, and updates tests accordingly.

In build_details, we first attempt to parse the details argument as JSON.
If successful, we pull out the `consoleLog` key and store it to be used
to build the console logs section. If JSON parsing failed, we assume we
received a (legacy) string, and pass that into get_details.

Inside of get_details, if we're able to access the items() member of the
details dict, we return the formatted string as a group of <li>s, otherwise
if we get an AttributeError (which happens for a string, or other non-dict
type), we just return the string as-is.

When building the console section of details, if there are not any logs,
it will just render as an empty string. But if there are logs, we return a
new section with the content inside a <pre> tag. This is handled by the new
get_console_section method.
@miketaylr
Copy link
Member Author

OK, approach slightly changed. I'm still using a hidden input here, because if we stick it inside <pre>, we don't have the linking problems. Will experiment with a textarea and something that isn't a single line in the follow up bug.

r? @karlcow

@miketaylr
Copy link
Member Author

screen shot 2018-10-18 at 10 34 41 pm

Copy link
Member

@karlcow karlcow left a comment

Choose a reason for hiding this comment

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

@miketaylr You could have use a dict comprehension in…

just kidding 🤣

This is cool. Thanks.

@miketaylr
Copy link
Member Author

@miketaylr You could have use a dict comprehension in…

haha <3

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