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

[server] Fix quotes in system comments #3094

Merged

Conversation

csordasmarton
Copy link
Contributor

Closes #3092

Commenting on an issue using quotes results to the error
"No closing quotation" because of shlex.split.

@@ -1613,6 +1613,7 @@ def getComments(self, report_id):
sys_comment = comment_kind_from_thrift_type(
ttypes.CommentKind.SYSTEM)
if comment.kind == sys_comment:
message = message.replace("'", "\\'")
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is enough. What if it contains double quotes, or backticks, or other shell-special characters? Maybe shlex.quote() works good for you? Not sure, since I don't understand what shlex.split() is used for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jimis Good point, you are right. I changed it to use the shlex.quote function and I've also extended the test case with more special characters.

@csordasmarton csordasmarton force-pushed the fix_quotes_in_system_comments branch from 0368b80 to 2610836 Compare December 14, 2020 08:34
@csordasmarton csordasmarton added the WIP 💣 Work In Progress label Dec 14, 2020
@csordasmarton csordasmarton force-pushed the fix_quotes_in_system_comments branch from 2610836 to 50e14c6 Compare December 15, 2020 08:49
@csordasmarton csordasmarton removed the WIP 💣 Work In Progress label Dec 15, 2020
@jimis
Copy link
Contributor

jimis commented Dec 15, 2020

I verify that this fixes the issue: quotes are possible to be inserted, and the previously impossible-to-view comments, are now viewable. So +1 from me.

On a side discussion however, it might be worth deprecating "status change comments" alltogether. They look ugly (they merge newlines and paragraphs), and when someone writes two-three paragraphs explaining why the issue is a false-positive, it's hard to read.

By disabling the addition of new "status change comments", people will add separate comments after changing the status. They preserve all formatting and are easier to read.

@csordasmarton
Copy link
Contributor Author

@jimis Could you please give us a screenshot from an ugly comment? How it looks like?

@jimis
Copy link
Contributor

jimis commented Dec 15, 2020

Here is almost the same comment written within the status change, and as a separate comment. You can see that in the first case all whitespace is lost, and the comment comes in small letters.

codechecker_ugly_system_comments-Screenshot_2020-12-15 CodeChecker viewer

@csordasmarton csordasmarton force-pushed the fix_quotes_in_system_comments branch from 50e14c6 to 4e0c80b Compare January 12, 2021 09:52
Copy link
Contributor

@bruntib bruntib left a comment

Choose a reason for hiding this comment

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

The changes look good, at least it is not necessarily a "request changes" review. But let's just discuss shortly the issue I wrote.

new_review_status = \
escape_whitespaces(review_status.status.capitalize())
old_review_status = shlex.quote(old_status.capitalize())
new_review_status = shlex.quote(review_status.status.capitalize())
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the value of return statuses is determined by review_status_str(), there is no special character to escape. So these shlex.quote() calls don't change the strings.

# without escaping special characters such as
# quotes. This is kept only for backward
# compatibility reason.
elements = shlex.split(shlex.quote(message))
Copy link
Contributor

Choose a reason for hiding this comment

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

The result of shlex.split() on the result of shlex.quote() will always be a one-element list. This is not suitable for checking whether the first element is an indicator of system comments. So in this environment this line is equivalent with pass, I mean system comments stored with old CodeChecker version will not be formatted in either case. Another option would be to use simple string split, because it works both for rev_st_changed and rev_st_changed_msg but not for comment_changed if the comment contains spaces.

@csordasmarton csordasmarton added this to the release 6.15.1 milestone Jan 25, 2021
Commenting on an issue using quotes results to the error
"No closing quotation" because of `shlex.split`.
@csordasmarton csordasmarton force-pushed the fix_quotes_in_system_comments branch from 4e0c80b to 38cd5a1 Compare January 29, 2021 09:37
@csordasmarton csordasmarton requested a review from bruntib January 29, 2021 09:38
@bruntib bruntib merged commit ffd0d46 into Ericsson:master Jan 29, 2021
@csordasmarton csordasmarton deleted the fix_quotes_in_system_comments branch March 10, 2021 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Commenting on an issue using quotes results to the error "No closing quotation"
3 participants