aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java6
-rw-r--r--sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java11
-rw-r--r--sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java2
-rw-r--r--sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java6
4 files changed, 16 insertions, 9 deletions
diff --git a/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java b/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java
index 2358e0bfa44..50359838d72 100644
--- a/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java
+++ b/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java
@@ -240,14 +240,14 @@ public class CodeBuffer implements CharSequence {
}
/**
- * Warning : this method always returns Integer.MAX_VALUE as the length of the stream can't be known before having consumed all
- * characters.
+ * Warning : this method returns Integer.MAX_VALUE when the buffer is fully used
+ * as the length of the stream can't be known before having consumed all characters.
*
* Integer.MAX_VALUE is returned to prevent regular expression matchers to stop consuming the stream of characters (see
* http://jira.codehaus.org/browse/SONAR-2010)
*/
public final int length() {
- return (bufferSize == bufferCapacity ? Integer.MAX_VALUE : bufferSize);
+ return (bufferSize == bufferCapacity ? Integer.MAX_VALUE : bufferSize - bufferPosition);
}
public final CharSequence subSequence(int start, int end) {
diff --git a/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java b/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java
index e5befb2efcb..471b16bd975 100644
--- a/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java
+++ b/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java
@@ -197,7 +197,16 @@ public class CodeBufferTest {
@Test
public void theLengthShouldBeTheSameThanTheStringLength() {
String myCode = "myCode";
- assertThat(new CodeBuffer(myCode, new CodeReaderConfiguration()).length(), is(myCode.length()));
+ assertThat(new CodeBuffer(myCode, new CodeReaderConfiguration()).length(), is(6));
+ }
+
+ @Test
+ public void theLengthShouldDecreaseEachTimeTheInputStreamIsConsumed() {
+ String myCode = "myCode";
+ CodeBuffer codeBuffer = new CodeBuffer(myCode, new CodeReaderConfiguration());
+ codeBuffer.pop();
+ codeBuffer.pop();
+ assertThat(codeBuffer.length(), is(4));
}
@Test
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 392a37aa345..d59b3f3adb2 100644
--- a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java
+++ b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java
@@ -29,7 +29,7 @@ import org.sonar.channel.RegexChannel;
class HtmlEmphasisChannel extends RegexChannel<MarkdownOutput> {
public HtmlEmphasisChannel() {
- super("\\*[^\n\r\\*\\s]++\\*");
+ super("\\*[^\\s\\*][^\n\r]+?[^\\s\\*]\\*");
}
@Override
diff --git a/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java b/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java
index 9579828af9b..cf4a0f1b726 100644
--- a/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java
+++ b/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java
@@ -39,6 +39,7 @@ public class MarkdownEngineTest {
@Test
public void shouldDecorateList() {
assertThat(MarkdownEngine.convertToHtml(" * one\r* two\r\n* three\n * \n *five"), is("<ul><li>one</li>\r<li>two</li>\r\n<li>three</li>\n<li> </li>\n</ul> *five"));
+ assertThat(MarkdownEngine.convertToHtml(" * one\r* two"), is("<ul><li>one</li>\r<li>two</li></ul>"));
}
@Test
@@ -56,10 +57,7 @@ public class MarkdownEngineTest {
assertThat(MarkdownEngine.convertToHtml("Not *emphase * because of whitespace"), is("Not *emphase * because of whitespace"));
assertThat(MarkdownEngine.convertToHtml("Not * emphase* because of whitespace"), is("Not * emphase* because of whitespace"));
assertThat(MarkdownEngine.convertToHtml("emphase*inside*word"), is("emphase<em>inside</em>word"));
-
- // not supported yet
- // assertThat(MarkdownEngine.convertToHtml("\\*surrounded by literal asterisks\\*"), is("\\*surrounded by literal asterisks\\*"));
-
+ assertThat(MarkdownEngine.convertToHtml("*Emphase many words*"), is("<em>Emphase many words</em>"));
}
@Test