]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9857 fixing regexp to allow short emphasised string
authorGuillaume Jambet <guillaume.jambet@sonarsource.com>
Wed, 29 Nov 2017 14:23:30 +0000 (15:23 +0100)
committerGuillaume Jambet <guillaume.jambet@gmail.com>
Tue, 5 Dec 2017 23:37:59 +0000 (00:37 +0100)
sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java
sonar-markdown/src/test/java/org/sonar/markdown/MarkdownTest.java
tests/src/test/java/org/sonarqube/tests/Category6Suite.java
tests/src/test/java/org/sonarqube/tests/rule/RulesMarkdownTest.java [new file with mode: 0644]

index 7a5621aafee3e14a1434db82743aaac9c840bdb4..d35a9c008a335725f8ddb58a540e02ca910ddd7b 100644 (file)
@@ -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
index 794b86821f50df55ed2b4317c2bfac48510d3a35..fb92e1de64363e53286ba8bf34cf58ed8bdd267c 100644 (file)
@@ -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
index 9cb93ba6474586a0af2a1c7a8e8a1cfe9a589fc0..cc7f72cf23aec8dcec81eaf164856fa7d8fe418e 100644 (file)
@@ -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 (file)
index 0000000..0571102
--- /dev/null
@@ -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);
+  }
+
+}