aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java4
-rw-r--r--sonar-markdown/src/test/java/org/sonar/markdown/MarkdownTest.java17
-rw-r--r--tests/src/test/java/org/sonarqube/tests/Category6Suite.java2
-rw-r--r--tests/src/test/java/org/sonarqube/tests/rule/RulesMarkdownTest.java78
4 files changed, 91 insertions, 10 deletions
diff --git a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java
index 7a5621aafee..d35a9c008a3 100644
--- a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java
+++ b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java
@@ -28,8 +28,8 @@ import org.sonar.channel.RegexChannel;
*/
class HtmlEmphasisChannel extends RegexChannel<MarkdownOutput> {
- public HtmlEmphasisChannel() {
- super("\\*[^\\s\\*][^\n\r]+?[^\\s\\*]\\*");
+ HtmlEmphasisChannel() {
+ super("\\*[^\\s\\*]\\*|\\*[^\\s\\*][^\n\r]*?[^\\s\\*]\\*");
}
@Override
diff --git a/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownTest.java b/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownTest.java
index 794b86821f5..fb92e1de643 100644
--- a/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownTest.java
+++ b/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownTest.java
@@ -100,15 +100,16 @@ public class MarkdownTest {
}
@Test
- public void shouldEmphaseText() {
- assertThat(Markdown.convertToHtml("This is *important*")).isEqualTo("This is <strong>important</strong>");
- assertThat(Markdown.convertToHtml("This should not be * \n emphase")).isEqualTo("This should not be * <br/> emphase");
+ public void shouldEmphasisText() {
+ assertThat(Markdown.convertToHtml("This is *Sparta !!!*")).isEqualTo("This is <strong>Sparta !!!</strong>");
+ assertThat(Markdown.convertToHtml("This is *A*")).isEqualTo("This is <strong>A</strong>");
+ assertThat(Markdown.convertToHtml("This should not be * \n emphasized")).isEqualTo("This should not be * <br/> emphasized");
assertThat(Markdown.convertToHtml("This is *very* very *important*")).isEqualTo("This is <strong>very</strong> very <strong>important</strong>");
- assertThat(Markdown.convertToHtml("Not * emphase * because of whitespaces")).isEqualTo("Not * emphase * because of whitespaces");
- assertThat(Markdown.convertToHtml("Not *emphase * because of whitespace")).isEqualTo("Not *emphase * because of whitespace");
- assertThat(Markdown.convertToHtml("Not * emphase* because of whitespace")).isEqualTo("Not * emphase* because of whitespace");
- assertThat(Markdown.convertToHtml("emphase*inside*word")).isEqualTo("emphase<strong>inside</strong>word");
- assertThat(Markdown.convertToHtml("*Emphase many words*")).isEqualTo("<strong>Emphase many words</strong>");
+ assertThat(Markdown.convertToHtml("Not * emphasized * because of whitespaces")).isEqualTo("Not * emphasized * because of whitespaces");
+ assertThat(Markdown.convertToHtml("Not *emphasized * because of whitespace")).isEqualTo("Not *emphasized * because of whitespace");
+ assertThat(Markdown.convertToHtml("Not * emphasized* because of whitespace")).isEqualTo("Not * emphasized* because of whitespace");
+ assertThat(Markdown.convertToHtml("emphasized*inside*word")).isEqualTo("emphasized<strong>inside</strong>word");
+ assertThat(Markdown.convertToHtml("*Emphasize many words*")).isEqualTo("<strong>Emphasize many words</strong>");
}
@Test
diff --git a/tests/src/test/java/org/sonarqube/tests/Category6Suite.java b/tests/src/test/java/org/sonarqube/tests/Category6Suite.java
index 9cb93ba6474..cc7f72cf23a 100644
--- a/tests/src/test/java/org/sonarqube/tests/Category6Suite.java
+++ b/tests/src/test/java/org/sonarqube/tests/Category6Suite.java
@@ -35,6 +35,7 @@ import org.sonarqube.tests.qualityProfile.BuiltInQualityProfilesTest;
import org.sonarqube.tests.qualityProfile.CustomQualityProfilesTest;
import org.sonarqube.tests.qualityProfile.QualityProfilesEditTest;
import org.sonarqube.tests.qualityProfile.QualityProfilesWsTest;
+import org.sonarqube.tests.rule.RulesMarkdownTest;
import org.sonarqube.tests.rule.RulesWsTest;
import org.sonarqube.tests.user.OrganizationIdentityProviderTest;
@@ -59,6 +60,7 @@ import static util.ItUtils.xooPlugin;
CustomQualityProfilesTest.class,
IssueTagsTest.class,
RulesWsTest.class,
+ RulesMarkdownTest.class,
PermissionTemplateTest.class,
ReportFailureNotificationTest.class,
IssueNotificationsTest.class
diff --git a/tests/src/test/java/org/sonarqube/tests/rule/RulesMarkdownTest.java b/tests/src/test/java/org/sonarqube/tests/rule/RulesMarkdownTest.java
new file mode 100644
index 00000000000..0571102f1cf
--- /dev/null
+++ b/tests/src/test/java/org/sonarqube/tests/rule/RulesMarkdownTest.java
@@ -0,0 +1,78 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonarqube.tests.rule;
+
+import com.sonar.orchestrator.Orchestrator;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.qa.util.Tester;
+import org.sonarqube.tests.Category6Suite;
+import org.sonarqube.ws.Organizations;
+import org.sonarqube.ws.Organizations.Organization;
+import org.sonarqube.ws.Rules.ShowResponse;
+import org.sonarqube.ws.client.rules.ShowRequest;
+import org.sonarqube.ws.client.rules.UpdateRequest;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class RulesMarkdownTest {
+
+ private static final String RULE_HAS_TAG = "xoo:HasTag";
+
+ @ClassRule
+ public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
+
+ @Rule
+ public Tester tester = new Tester(orchestrator);
+
+ @Test
+ public void use_markdown_in_description() {
+ Organization organization = tester.organizations().generate();
+
+ tester.wsClient().rules().update(createUpdateRequest(organization, "*my custom note*"));
+
+ ShowResponse showResponse = tester.wsClient().rules().show(createShowRequest(organization));
+ assertThat(showResponse.getRule().getMdNote()).isEqualTo("*my custom note*");
+ assertThat(showResponse.getRule().getHtmlNote()).isEqualTo("<strong>my custom note</strong>");
+ }
+
+ @Test
+ public void use_markdown_for_short_string() {
+ Organization organization = tester.organizations().generate();
+ String markdownNote = "*A*";
+ String expected = "<strong>A</strong>";
+
+ tester.wsClient().rules().update(createUpdateRequest(organization, markdownNote));
+
+ ShowResponse showResponse = tester.wsClient().rules().show(createShowRequest(organization));
+ assertThat(showResponse.getRule().getMdNote()).isEqualTo(markdownNote);
+ assertThat(showResponse.getRule().getHtmlNote()).isEqualTo(expected);
+ }
+
+ private static ShowRequest createShowRequest(Organization organization) {
+ return new ShowRequest().setKey(RULE_HAS_TAG).setOrganization(organization.getKey());
+ }
+
+ private static UpdateRequest createUpdateRequest(Organization organization, String markdownNote) {
+ return new UpdateRequest().setKey(RULE_HAS_TAG).setOrganization(organization.getKey()).setMarkdownNote(markdownNote);
+ }
+
+}