From 79f9c59c24977943bc5ae8d34bffcce9a4d6ba38 Mon Sep 17 00:00:00 2001 From: Guillaume Jambet Date: Wed, 29 Nov 2017 15:23:30 +0100 Subject: SONAR-9857 fixing regexp to allow short emphasised string --- .../java/org/sonar/markdown/HtmlEmphasisChannel.java | 4 ++-- .../src/test/java/org/sonar/markdown/MarkdownTest.java | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'sonar-markdown/src') 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 { - 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 important"); - assertThat(Markdown.convertToHtml("This should not be * \n emphase")).isEqualTo("This should not be *
emphase"); + public void shouldEmphasisText() { + assertThat(Markdown.convertToHtml("This is *Sparta !!!*")).isEqualTo("This is Sparta !!!"); + assertThat(Markdown.convertToHtml("This is *A*")).isEqualTo("This is A"); + assertThat(Markdown.convertToHtml("This should not be * \n emphasized")).isEqualTo("This should not be *
emphasized"); assertThat(Markdown.convertToHtml("This is *very* very *important*")).isEqualTo("This is very very important"); - 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("emphaseinsideword"); - assertThat(Markdown.convertToHtml("*Emphase many words*")).isEqualTo("Emphase many words"); + 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("emphasizedinsideword"); + assertThat(Markdown.convertToHtml("*Emphasize many words*")).isEqualTo("Emphasize many words"); } @Test -- cgit v1.2.3