Skip to content

Default Parser error (Repro included) #667

@sjorn3

Description

@sjorn3

Describe the bug A clear and concise description of what the bug is.

With default parser settings in flexmark 0.64.8 I'm getting an internal accumulator bug with the following minimal input. It's not valid markdown but my understanding is that it should be supported or at least give a more useful error.

x\n \n`\n x\n`
FAIL: java.lang.IllegalStateException: Accumulated range [5, 6) overlaps Transformed Range[2]: [5, 6)
java.lang.IllegalStateException: Accumulated range [5, 6) overlaps Transformed Range[2]: [5, 6)
        at com.vladsch.flexmark.util.sequence.builder.SegmentBuilderBase.processParts(SegmentBuilderBase.java:431)
        at com.vladsch.flexmark.util.sequence.builder.SegmentBuilderBase.append(SegmentBuilderBase.java:538)
        at com.vladsch.flexmark.util.sequence.builder.SegmentBuilderBase.append(SegmentBuilderBase.java:16)
        at com.vladsch.flexmark.util.sequence.builder.tree.SegmentTree.addSegments(SegmentTree.java:325)

Expected behavior A clear and concise description of what you expected to happen with sample output that would be desired, where it makes sense.

Ideally I would get a best effort at the text without markdown when calling TextCollectingVisitor().collectAndGetText, but largely just reporting the internal error.

Code to reproduce

import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.ast.TextCollectingVisitor;

public class FlexmarkDefaultCheck {
  public static void main(String[] args) {
    String s = "x\n \n`\n x\n`";
    try {
      Parser p = Parser.builder().build();
      Node doc = p.parse(s);
      String out = new TextCollectingVisitor().collectAndGetText(doc);
      System.out.println("OK");
      System.out.println(out.replace("\n", "\\n"));
    } catch (Throwable t) {
      t.printStackTrace();
      System.exit(1);
    }
  }
}

Thank you for looking into it!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions