Skip to content

StringIndexOutOfBoundsException on empty ordered list input. #13

@jleyba

Description

@jleyba

Using com.atlassian.commonmark:commonmark:0.1.0:

import static org.junit.Assert.assertEquals;

import org.commonmark.html.HtmlRenderer;
import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class MarkdownTest {
  @Test
  public void shouldWork() {
    Parser parser = Parser.builder().build();
    Node root = parser.parse("2.");

    HtmlRenderer renderer = HtmlRenderer.builder().escapeHtml(false).build();
    String html = renderer.render(root);

    assertEquals(
        "<ol start=\"2\">\n" +
            "<li></li>\n" +
            "</ol>",
        html);
  }
}

The test above fails with:

java.lang.StringIndexOutOfBoundsException: String index out of range: 2
  at java.lang.String.charAt(String.java:658)
  at org.commonmark.internal.util.Substring.charAt(Substring.java:32)
  at java.lang.Character.codePointAt(Character.java:4668)
  at org.commonmark.internal.util.Parsing.isLetter(Parsing.java:55)
  at org.commonmark.internal.DocumentParser.incorporateLine(DocumentParser.java:194)
  at org.commonmark.internal.DocumentParser.parse(DocumentParser.java:83)
  at org.commonmark.parser.Parser.parse(Parser.java:45)
  at MarkdownTest.shouldWork(MarkdownTest.java:32)

For reference, here's the output for commonmark.js: http://spec.commonmark.org/dingus/?text=2.

Edit Fixed rendering of dingus link

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions