Fix directive body_offset inflated by one when body ends in blank lines#1179
Open
dchaudhari7177 wants to merge 2 commits into
Open
Fix directive body_offset inflated by one when body ends in blank lines#1179dchaudhari7177 wants to merge 2 commits into
dchaudhari7177 wants to merge 2 commits into
Conversation
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.
Fixes #1177.
body_offset(the number of lines from a directive's opening line to its first body line) was inflated by one whenever a directive had an option block and its body ended in blank line(s)._parse_directive_optionsreturns the body as a string built with"\n".join(...), andparse_directive_textre-split it and derived the offset aslen(content.splitlines()) - len(body_lines). The join→split round-trip drops exactly one trailing blank line, solen(body_lines)was one short and the offset one too high — every body element was then reported one source line too low.Fix:
_parse_directive_optionsnow reports the number of source lines the option block actually occupies (computed before the body is re-joined), andparse_directive_textuses that directly instead of the lossy subtraction. The count also correctly handles a---closer that carries trailing text (which becomes the first body line on the closing line itself).Verification
Added
test_body_offset_not_inflated_by_trailing_blank_linescovering colon- and YAML-style option blocks, with and without trailing blanks — it fails onmainand passes here. The fulltest_parse_directives.pysuite (including the snapshot fixtures and the trailing-closing-text case) stays green.