Repository navigation
Conversation
In commonmark@0982a26, `LinkReferenceDefinitionParser` started keeping committed link-reference source spans at the front of `sourceSpans` (`0..referenceSourceSpanCount`) until `finishReference` runs. When a block parser calls `replaceActiveBlockParser` or `replaceParagraphLines` with more lines than the uncommitted paragraph lines (such as `Integer.MAX_VALUE`), `removeLines` strips past `referenceSourceSpanCount` and `finishReference` throws `IndexOutOfBoundsException`. To avoid this, clamp `removeLines` to the uncommitted trailing paragraph spans and clear that slice directly. Here are the failures for the new tests before the prod change: ``` [ERROR] org.commonmark.test.BlockParserFactoryTest.replaceActiveBlockParserAfterLinkReferenceDefinitionWithUnclosedTitle -- Time elapsed: 0.002 s <<< ERROR! java.lang.IndexOutOfBoundsException: toIndex = 1 at java.base/java.util.AbstractList.subListRangeCheck(AbstractList.java:509) at java.base/java.util.ArrayList.subList(ArrayList.java:1199) at org.commonmark@0.33.1-SNAPSHOT/org.commonmark.internal.LinkReferenceDefinitionParser.finishReference(LinkReferenceDefinitionParser.java:300) at org.commonmark@0.33.1-SNAPSHOT/org.commonmark.internal.LinkReferenceDefinitionParser.getDefinitions(LinkReferenceDefinitionParser.java:110) at org.commonmark@0.33.1-SNAPSHOT/org.commonmark.internal.ParagraphParser.getDefinitions(ParagraphParser.java:53) at org.commonmark@0.33.1-SNAPSHOT/org.commonmark.internal.DocumentParser.addDefinitionsFrom(DocumentParser.java:595) at org.commonmark@0.33.1-SNAPSHOT/org.commonmark.internal.DocumentParser.finalize(DocumentParser.java:590) at org.commonmark@0.33.1-SNAPSHOT/org.commonmark.internal.DocumentParser.closeBlockParsers(DocumentParser.java:577) at org.commonmark@0.33.1-SNAPSHOT/org.commonmark.internal.DocumentParser.replaceParagraphLines(DocumentParser.java:553) at org.commonmark@0.33.1-SNAPSHOT/org.commonmark.internal.DocumentParser.parseLine(DocumentParser.java:297) at org.commonmark@0.33.1-SNAPSHOT/org.commonmark.internal.DocumentParser.parse(DocumentParser.java:138) at org.commonmark@0.33.1-SNAPSHOT/org.commonmark.parser.Parser.parse(Parser.java:89) at org.commonmark@0.33.1-SNAPSHOT/org.commonmark.test.BlockParserFactoryTest.replaceActiveBlockParserAfterLinkReferenceDefinitionWithUnclosedTitle(BlockParserFactoryTest.java:68) at java.base/java.lang.reflect.Method.invoke(Method.java:583) at java.base/java.util.ArrayList.forEach(ArrayList.java:1612) at java.base/java.util.ArrayList.forEach(ArrayList.java:1612) ``` ``` [ERROR] org.commonmark.internal.LinkReferenceDefinitionParserTest.testRemoveLinesWithoutParagraphLinesPreservesCommittedReferenceSourceSpans -- Time elapsed: 0.004 s <<< FAILURE! java.lang.AssertionError: Expecting empty but was: [SourceSpan{line=0, column=0, input=0, length=11}] at org.commonmark@0.33.1-SNAPSHOT/org.commonmark.internal.LinkReferenceDefinitionParserTest.testRemoveLinesWithoutParagraphLinesPreservesCommittedReferenceSourceSpans(LinkReferenceDefinitionParserTest.java:261) at java.base/java.lang.reflect.Method.invoke(Method.java:583) at java.base/java.util.ArrayList.forEach(ArrayList.java:1612) at java.base/java.util.ArrayList.forEach(ArrayList.java:1612) ``` ``` [ERROR] org.commonmark.internal.LinkReferenceDefinitionParserTest.testRemoveLinesPreservesCommittedReferenceSourceSpans -- Time elapsed: 0.002 s <<< FAILURE! org.opentest4j.AssertionFailedError: Expecting actual: [SourceSpan{line=0, column=0, input=0, length=11}, SourceSpan{line=1, column=0, input=12, length=6}] to contain exactly (and in same order): [SourceSpan{line=1, column=0, input=12, length=6}] but some elements were not expected: [SourceSpan{line=0, column=0, input=0, length=11}] at org.commonmark@0.33.1-SNAPSHOT/org.commonmark.internal.LinkReferenceDefinitionParserTest.testRemoveLinesPreservesCommittedReferenceSourceSpans(LinkReferenceDefinitionParserTest.java:243) at java.base/java.lang.reflect.Method.invoke(Method.java:583) at java.base/java.util.ArrayList.forEach(ArrayList.java:1612) at java.base/java.util.ArrayList.forEach(ArrayList.java:1612) ```
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In 0982a26,
LinkReferenceDefinitionParserstarted keeping committed link-reference source spans at the front ofsourceSpans(0..referenceSourceSpanCount) untilfinishReferenceruns. When a block parser callsreplaceActiveBlockParserorreplaceParagraphLineswith more lines than the uncommitted paragraph lines (such asInteger.MAX_VALUE),removeLinesstrips pastreferenceSourceSpanCountandfinishReferencethrowsIndexOutOfBoundsException.To avoid this, clamp
removeLinesto the uncommitted trailing paragraph spans and clear that slice directly.Here are the failures for the new tests before the prod change: