From 13af20dce3f2252aac9e9e1c4d3d75a0bdb779d5 Mon Sep 17 00:00:00 2001 From: Alain Kermis Date: Wed, 31 Jan 2024 14:49:45 +0100 Subject: [PATCH] SONAR-21059 Fix incorrect character encoding in email subject --- .../issue/notification/ChangesOnMyIssuesEmailTemplate.java | 4 +--- .../issue/notification/IssueChangesEmailTemplate.java | 7 +++++++ .../notification/ChangesOnMyIssuesEmailTemplateTest.java | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssuesEmailTemplate.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssuesEmailTemplate.java index 57fef428c9e..250f17973c4 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssuesEmailTemplate.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssuesEmailTemplate.java @@ -75,9 +75,7 @@ public class ChangesOnMyIssuesEmailTemplate extends IssueChangesEmailTemplate { } private static String buildAnalysisSubject(Project project) { - StringBuilder res = new StringBuilder("Analysis has changed some of your issues in "); - toString(res, project); - return res.toString(); + return "Analysis has changed some of your issues in " + toSubject(project); } private String buildAnalysisMessage(Project project, ChangesOnMyIssuesNotification notification) { diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssueChangesEmailTemplate.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssueChangesEmailTemplate.java index f28fa1bc835..8ba368894ab 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssueChangesEmailTemplate.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssueChangesEmailTemplate.java @@ -81,6 +81,13 @@ public abstract class IssueChangesEmailTemplate implements EmailTemplate { this.settings = settings; } + /** + * Used to build the subject for the email + */ + protected static String toSubject(Project project) { + return project.getProjectName() + project.getBranchName().map(branchName -> " (" + branchName + ")").orElse(""); + } + /** * Adds "projectName" or "projectName, branchName" if branchName is non null */ diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssuesEmailTemplateTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssuesEmailTemplateTest.java index 54a88f6cccc..4205cfd7ed9 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssuesEmailTemplateTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssuesEmailTemplateTest.java @@ -137,7 +137,7 @@ public class ChangesOnMyIssuesEmailTemplateTest { EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, changedIssues)); Project project = changedIssues.iterator().next().getProject(); - assertThat(emailMessage.getSubject()).isEqualTo("Analysis has changed some of your issues in " + project.getProjectName() + ", " + project.getBranchName().get()); + assertThat(emailMessage.getSubject()).isEqualTo("Analysis has changed some of your issues in " + project.getProjectName() + " (" + project.getBranchName().get() + ")"); } @Test -- 2.39.5