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

Newlines in custom data are shown as \n in emails #534

Closed
wants to merge 1 commit into from
Closed

Newlines in custom data are shown as \n in emails #534

wants to merge 1 commit into from

Conversation

scompt
Copy link

@scompt scompt commented Dec 5, 2016

Newlines are escaped in CustomDataCollector, presumably for a good reason somewhere else in the code. However, when I send a report via email, the custom data contains the escaped newlines (\n) in the custom data instead of real newlines. Is there just a step missing in EmailIntentSender?

This is the code I'm using to update the custom data. I'm keeping a log by appending messages to a single custom data key.

            String log = errorReporter.getCustomData(LOG_KEY);
            if (log == null) {
                log = fullMessage;
            } else {
                log = String.format("%s%n%s", log, fullMessage);
            }

            errorReporter.putCustomData(LOG_KEY, log);

I'm using version 4.9.1, but have also tested with the development version and the problem still exists.

@william-ferguson-au
Copy link
Member

What version of ACRA?

@scompt
Copy link
Author

scompt commented Dec 5, 2016

4.9.1

I haven't tested yet with the current state of the repository. I'll do that now.

@scompt
Copy link
Author

scompt commented Dec 5, 2016

@william-ferguson-au The probably also exists in the current code. I've updated the issue with some code.

@william-ferguson-au
Copy link
Member

Yeah, looks like you need to transform the customData from \\n back to \n

@scompt
Copy link
Author

scompt commented Dec 5, 2016

@william-ferguson-au I think I've fixed it with this pull request. Can you take a look?

@@ -66,8 +66,12 @@ private String buildBody(@NonNull CrashReportData errorContent) {

final StringBuilder builder = new StringBuilder();
for (ReportField field : fields) {
String value = errorContent.get(field);
if (value != null) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe value can ever be null. If it is listed as a field then it should always have a value. And the previous code would have broken on line 74 with an NullPointerException.

@@ -66,8 +66,12 @@ private String buildBody(@NonNull CrashReportData errorContent) {

final StringBuilder builder = new StringBuilder();
for (ReportField field : fields) {
String value = errorContent.get(field);
if (value != null) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe value can ever be null. If it is listed as a field then it should always have a value. And the previous code would have broken on line 74 with an NullPointerException.

Copy link
Member

Choose a reason for hiding this comment

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

Correct. There is a de-facto null-value, which is AcraConstants.NOT_AVAILABLE, but a collector returning null would be a bug.

@@ -66,8 +66,12 @@ private String buildBody(@NonNull CrashReportData errorContent) {

final StringBuilder builder = new StringBuilder();
for (ReportField field : fields) {
String value = errorContent.get(field);
if (value != null) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe value can ever be null. If it is listed as a field then it should always have a value. And the previous code would have broken on line 74 with an NullPointerException.

Copy link
Author

Choose a reason for hiding this comment

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

My first implementation didn't have the null check, but I got a NullPointerException. I didn't look into it any further, but I think it might be because the "user comment" was null. I've seen that in the email that gets sent. StringBuilder.append inserts "null" into the string if the argument is null, so I don't think anything will crash if a null is around.

@F43nd1r
Copy link
Member

F43nd1r commented Dec 5, 2016

Does this problem exist with the json implementation? See #523

If not, this would be another reason to adopt that structure.

@william-ferguson-au
Copy link
Member

@F43nd1r Kevin has added you as team member, so you can merge in these and other changes.
Thanks for your help.

@F43nd1r
Copy link
Member

F43nd1r commented Dec 9, 2016

@william-ferguson-au thanks for that. But I think it won't change much on my workflow, as I won't be merging anything without talking about it with you and/or Kevin.

While I would like to merge the json PR, I'll have to test it some more, as I noticed that the EmailSender will output some json, which should not be the case.

@F43nd1r
Copy link
Member

F43nd1r commented Dec 21, 2016

Closing because the problem was solved with #523

@F43nd1r F43nd1r closed this Dec 21, 2016
@scompt scompt deleted the custom_data_email_newlines branch December 21, 2016 08:40
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.

3 participants