You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: medium- and low-severity parser and formatter bugs found by property tests - #13
Escaping.normalizeEOL turned "\r\r" into a single "\n" and dropped a
trailing "\r", so blank lines vanished from fenced and indented code and
HTML blocks lost their last line ending when the document used lone CR
line endings (CommonMark 0.29 section 2.1).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ferences
The HTML writer only sees "\n" as a line end, so after a lone "\r" the
indent of the next line was kept in link and image titles, image alt
text and the literal text of an undefined reference, and "\r\n" was
written out as is. Normalize these strings like Text nodes already are.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Parser.BLOCK_NESTING_LIMIT (default 100, <= 0 disables). DocumentParser
skips a block start that would open a container deeper than the limit, so
the text stays in the deepest allowed container as paragraph text. The
renderers, Formatter and visitors recurse per nesting level and overflowed
a 1 MiB stack at a few hundred nested "- " or "> ".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CommonMark 0.29 6.5 allows parentheses in a non-angled link destination
only when they are escaped or balanced. LinkDestinationParser counted an
opening parenthesis but never checked the count at the end, so
`[x](a(b )` rendered as a link and `[r]: a(b` was swallowed as a
reference definition.
The parser now returns null when parentheses remain open, and
InlineParserImpl treats that as no destination. Jekyll macro mode keeps
its old behavior because LinkDestinationParserTest encodes unbalanced
results for it (test_Jekyll16, 18, 20, 21).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
render(Image) appended the URL opening marker before choosing between
translation spans and the other render purposes, and the non-translation
branch appended it again. An image destination in angle brackets gained
one "<" per pass: "" became "", which renders as a link
to "<a" ("<a"), and "" became "". Drop the second append,
as render(Link) does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…offset
Bracket.isStraddling compared paragraph-relative delimiter indices with
document offsets, so the check only worked for a paragraph starting at
offset 0. "a\n\n*[*]" rendered "<p>*[*]</p>" while "*[*]" rendered
"<em>[</em>]". Map the delimiter to document offsets before comparing.
Delimiters that pair with each other inside the brackets, such as the
translation placeholder in "**x [_3_] y**", no longer count as
straddling, so the reference is kept at every offset as the translation
formatter needs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every `](` started a destination scan that ran to the end of the input
when the parentheses never closed, so `[a](` repeated (also `[a](<`,
` parsed in quadratic time: 64 KB took about 0.6 s.
CommonMark 0.29 6.5 lets implementations limit parenthesis nesting (at
least 3 levels). LinkDestinationParser now rejects a destination with
more than 32 nested unescaped parentheses, which bounds each scan and
makes these inputs linear (64 KB now 11-20 ms).
Output changes only for destinations nested deeper than 32 levels:
`[l](` + 33 x `(` + `a` + 33 x `)` + `)` used to render as a link and
now stays literal text. 32 levels still render as a link.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A reference definition rendered AS_IS ended with blankLine(), which writes
the blank line with the current prefix. When the definition was the last
block of a block quote, that blank line became a ">" line, which the next
block quote then continued: ">- [r]: a\n\n>- b" was formatted as one block
quote "> - [r]: a\n>\n> - b". Use tailBlankLine(), which drops the block
quote marker when the node ends the block quote and keeps it otherwise.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DefinitionNodeFormatter took the marker from the chars before the first
child, so an empty item threw a NullPointerException and an item in a
block quote, whose child starts before the marker, threw a
StringIndexOutOfBoundsException. Take the marker from the node, end the
marker line of an empty item while the enclosing prefixes apply, and put
a block quote first child on the marker line like a list item does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An HTML block was written in pre-formatted mode with line() before
closePreFormatted(). In pre-formatted mode line() always ends a line, so
a block whose last content line already ended with EOL got an extra
empty line, written with the current prefix. At the end of the document
"<style" grew by one blank line per pass, and in a block quote the extra
">" line joined the next block quote: "> <div>\n\n> b" became one block
quote. Close pre-formatted mode first, as for HTML comment blocks.
An HTML block of type 1, 3, 4 or 5 whose end condition never matched
runs to the end of its container and takes a blank line after it as its
content, so "<style" rendered as "<style\n\n". When formatting, do not
add the tail blank line after such a block.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RefNode.collectText collected only the children of an undefined
reference, so "![[x]]()" gave alt="x" where CommonMark gives "[x]".
Collect the literal prefix and suffix around the children, as the HTML
renderer does for undefined references. Heading ids keep the old text
so existing anchors do not change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
renderBlockQuoteLike wrote the ">" marker only as the prefix of the lines
its children wrote. A block quote with no children, or only blank lines,
wrote no line, so ">" was formatted as an empty document and "> >" lost
the inner block quote. Write the marker on a line of its own for such a
block quote, followed by the usual tail blank line.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A definition item may start after a paragraph that later turns out to
hold only reference definitions ("[F]:_\n: &"), or inside an empty
item. With no paragraph left to split into terms, the item stayed as a
<dd> without a <dl>. The extension's spec renders a marker line with no
term as a paragraph, so make the item a paragraph that starts at its
marker, which matches the HTML of the same text without the extension.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The formatter writes the list item marker and then renders the item's
first block on the same line. Headings, thematic breaks, fenced code,
HTML blocks and footnote definitions start with blankLine(), which ended
the marker line and left a blank line, so the item ended empty and the
block followed the list: "- # a" became "- \n\n # a" (a heading after an
empty list) and "3) <u>" an HTML block after the list. Only
renderBlockQuoteLike honoured FIRST_LIST_ITEM_CHILD.
Add FormatterUtils.blankLineBeforeBlock, which skips the blank line for
the first block of a list item while FIRST_LIST_ITEM_CHILD is set, and
use it in those formatters. The flag stays set for descendants of the
first block, so the helper also checks that the node is the item's first
child.
With the block kept in the item, its tail blank line now separated two
items of a tight list and made it loose: "- # a\n- b". Add
FormatterUtils.tailBlankLineAfterBlock, which ends the last block of an
item without a blank line unless the list is loose (or LIST_ITEM_SPACING
is LOOSE), and use it for headings, thematic breaks and HTML blocks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
preProcessBlock parsed the paragraph's chars, which span the source and
so still hold the prefixes of continuation lines. In a block quote a
destination on the next line became ">/url", "> [a]:\n> /url" was not
a definition, and a title on the next line was lost. Parse the content
lines instead, as inline parsing does; offsets still map to the source.
The Reference node's chars span those content lines too, so the
Formatter does not write the block quote markers twice.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without a right margin the formatter writes the lines of a paragraph as
they are, each at the indent of its container. A continuation line that
was indented by 4 or more columns, or was a lazy continuation line, then
moved to the container's indent, where block syntax on it starts a new
block: "a\n - b" became a list, "]\n -" a setext heading, and the
lazy line in "- _\n=" (which cannot underline a setext heading) was
indented into the list item and underlined one.
After a soft or hard line break, when the source text of the next line
starts a block that can interrupt a paragraph (list item, ATX heading,
block quote, fence, thematic break, HTML block types 1 to 6) or is a
setext heading underline, write it indented by 4 columns, where it can
only continue the paragraph. Other continuation lines are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The parser trims the whitespace inside the brackets from the text of a
link, link reference and image reference, and the formatter wrote only
the trimmed text. The whitespace is part of the source: "[\t][o]" is not
a reference to "o" while "[][o]" is, and "[]([ \]](> ''))" became
"[]([\]](> ''))", where "\]" turns the text into a link.
Write the whitespace between the opening bracket and the text, and
between the text and the closing bracket, as in the source. Whitespace
with a line break is left out, since the soft line breaks of the text
write the line break.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The formatter wrote the whitespace between the opening bracket and the
label of a link reference, but not between the label and the closing
bracket, and wrote none for image references. "[- ]" became "[-]",
"![- ]" became "![-]", and "[\ ]" became "[\]", an escaped bracket:
"[a][\ ]" then rendered as "[a][]".
Write the whitespace on both sides of the label of link and image
references, as for the link text. The branches used when wrapping to a
right margin are left as they are: core_wrapping_spec.md example
"Wrap - Restore Spaces: 55" expects "[B ]" to be formatted as "[B]".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Before Java 20, Matcher.toMatchResult() copies the whole input, so every
match() and matchWithGroups() call was linear in the input length. spnl()
runs at every "](", which kept unclosed link destinations quadratic on
Java 11 and timed out the pathological tests on CI. Read the offsets
from the matcher directly.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Formatting can trigger a StackOverflowError on valid input, and unresolved findings identify quadratic scanning and parsing and round-trip correctness regressions.
Check for a thematic break without a regex: the repeated group recursed
once per marker and overflowed the stack on a long line. Treat zero
padded ordered list markers such as "01." as starting with 1, as the
parser does. Find the content line after a line break by binary search,
instead of scanning the paragraph's lines from the start for every
break.
Count the nesting depth for Parser.BLOCK_NESTING_LIMIT from the parser
that will accept the started blocks: addChild() closes the matched
parsers that cannot contain them, so "- a\n+ b" starts a sibling list,
not a nested one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
isStraddling paired an opener with any closer of the same character in
the bracket region, so in "*x [**a*]b*" the "**" run paired with one "*"
although its other "*" can pair outside of the brackets. Pair only runs
of the same length and treat the region as straddled otherwise, as it
was before delimiters inside the region could pair.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SimTocBlockParser.canContain() records the child it accepts, so asking
it for every block start broke the simulated TOC. Count the depth from
the active parser chain first and walk up with canContain() only when
that depth would reject the block start.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Active findings identify quadratic delimiter processing and regressions in emphasis pairing, resolved-image alt text, and undefined-reference whitespace preservation.
isDefined() is still false when an image reference is successfully resolved by a custom LinkResolver. CoreNodeRenderer.render(ImageRef) then collects text starting at that same node, so resolving ![photo] to /photo.png now produces alt="![photo]" instead of alt="photo". Please distinguish the resolved image being rendered from genuinely undefined references nested inside its description, so the new literal-bracket handling only applies to the latter.
Preserve line breaks in directly emitted reference labels
Reference labels are emitted directly from trimmed getReference() text, without SoftLineBreak children to restore omitted newlines. Skipping EOL-containing gaps changes the undefined reference [a][\n b] to [a][b], removing visible whitespace that the previous leading-whitespace call preserved. Preserve those gaps for directly emitted labels, and suppress them only when rendered children already supply the line breaks.
Check delimiter rules before pairing equal-length runs
Equal-length runs can still fail to pair: in *x [a***b***c] y*, EmphasisDelimiterProcessor.getDelimiterUse() rejects the inner triple runs under its multiple-of-three rule. Treating them as paired creates a tentative reference and discards delimiters that should match across the brackets, changing the rendered emphasis. Consult the configured delimiter processor's matching rules before accepting an internal pair, and add this equal-length regression case.
- Bracket.isStraddling keeps the unpaired openers in a stack per
delimiter character, so finding and removing the last one is constant
time, and pairs two runs only when the delimiter processor accepts
them and the runs only open and only close, so the "multiple of 3"
rule cannot keep them apart: "*x [a***b***c] y*" now renders as at
offset 0 before the straddling change.
- A rendered image reference collects the alt text from its children,
so an image reference that a link resolver resolves keeps "photo" as
alt text instead of "![photo]".
- The whitespace inside the brackets of a reference label keeps its
line breaks: the label is written from source text, with no soft line
break nodes, so "[a][\n b]" no longer becomes "[a][b]".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved defects mis-handle crossing emphasis pairs, leave image alt references stale after reference transfers, and duplicate list indentation, breaking formatter idempotence.
isDefined() can remain false after references are transferred into the document. For example, parse ![[x]](), then transfer references from a document containing [x]: /u: this branch still produces alt="[x]" instead of alt="x". Image alt collection visits descendants directly, bypassing the renderer's undefined-reference recheck. Please recheck descendant references against the current document before treating their brackets as literal.
- Treat crossing emphasis pairs inside brackets as straddling: the inner
pair removes the openers between its runs, which moves the outer pair.
- Look up references in the document when collecting the text of an
undefined reference, so references transferred after parsing count.
- Write only the line break of a reference label gap: the writer adds the
container prefix, so copying it from the source doubled the indent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because unpublished findings identify formatting-induced parsing changes, nesting-limit violations, and incorrect multiline reference text.
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
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.
概要
プロパティテスト(ephyra)で見つかった不具合のうち、#12 で扱わなかった中・低重大度のものを修正します。パーサーの扱いが CommonMark と違う件、深い入れ子や閉じない括弧で処理が重くなる・スタックオーバーフローする件、Formatter が出力の意味を変えてしまう件が中心です。修正ごとにテストを追加し、各モジュールのテストスイートに登録しています。
修正内容
パーサー・HTML 出力
Escaping.normalizeEOLで単独の CR を改行として扱う。タイトル、alt、未定義参照の文字列も改行を正規化する-や>を数百段入れ子にすると、描画・Formatter・Visitor がスタックオーバーフローするParser.BLOCK_NESTING_LIMITを追加(既定 100、0 以下で無効)。上限を超えるコンテナは開かず、段落のテキストとして残す[x](a(b )がリンクになり、[r]: a(bが参照定義として消える[a](の繰り返しで処理時間が入力長の 2 乗になる(64 KB で約 0.6 秒)*[*]とa\n\n*[*])Bracket.isStraddlingで段落内の位置と文書内の位置を比べていた。文書内の位置に揃える![[x]]()の alt がxになる(CommonMark では[x])<dl>のない<dd>になるFormatter
<が整形のたびに増える(→)<を 2 回書いていたので 1 回にするtailBlankLine()で書き、引用の終わりでは>を付けない>だけの引用が消え、> >の内側の引用が消える- # a→ 空のリストと見出し)FormatterUtils.blankLineBeforeBlockとtailBlankLineAfterBlockを追加し、項目の最初のブロックの前に空行を入れない。タイトなリストがルーズにならないようにする[\t][o]が[o]への参照になる)[\ ]が[\]になる挙動が変わる点
Parser.BLOCK_NESTING_LIMIT(既定 100)を追加しました。ブロックコンテナが 100 段を超える入れ子は、それ以上開かずに段落のテキストになります。[x](a(b )など)はリンクになりません。括弧の入れ子が 33 段以上のリンク先もリンクになりません。flexmark-integration-testのpom.xmlに、テスト用の依存(flexmark-ext-definition)を追加しました。未修正のもの
![× 1000 など)や~~の多用による処理時間は、このブランチでは扱っていません。テスト
mvn -o test -pl '!flexmark-osgi':9,418 件すべて通過しました。スキップは 145 件です(flexmark-osgi はオフラインでプラグインを取得できないため除外)。Generated with Claude Code