Fix trailing newline loss when scrubbing sensitive lines#229
Merged
Conversation
Regression from #225: the _split_line_preserve_whitespace function incorrectly detected leading/trailing whitespace. When re.split is called with a capturing group on a string with leading/trailing whitespace, it produces empty strings at the boundaries: re.split(r"(\s+)", " foo\n") -> ['', ' ', 'foo', '\n', ''] The code was checking parts[0] and parts[-1] for whitespace, but those are empty strings. The actual whitespace is at parts[1] and parts[-2]. Fix: drop empty strings at boundaries before processing, simplifying the leading/trailing whitespace detection. ---- Prompt: ``` Hey I ran netconan on ~/networks/2026-02-04-.../ and got this diff. Did we mess up the newlines somewhere? We're now commenting out the closing brace. ``` commit-id:c8455062
dhalperi
commented
Feb 5, 2026
Member
Author
dhalperi
left a comment
There was a problem hiding this comment.
@dhalperi reviewed 2 files and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved.
dhalperi
added a commit
that referenced
this pull request
Feb 5, 2026
Regression from #225: the _split_line_preserve_whitespace function incorrectly detected leading/trailing whitespace. When re.split is called with a capturing group on a string with leading/trailing whitespace, it produces empty strings at the boundaries: re.split(r"(\s+)", " foo\n") -> ['', ' ', 'foo', '\n', ''] The code was checking parts[0] and parts[-1] for whitespace, but those are empty strings. The actual whitespace is at parts[1] and parts[-2]. Fix: drop empty strings at boundaries before processing, simplifying the leading/trailing whitespace detection. ---- Prompt: ``` Hey I ran netconan on ~/networks/2026-02-04-.../ and got this diff. Did we mess up the newlines somewhere? We're now commenting out the closing brace. ``` commit-id:c8455062
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.
Regression from #225: the _split_line_preserve_whitespace function
incorrectly detected leading/trailing whitespace. When re.split is
called with a capturing group on a string with leading/trailing
whitespace, it produces empty strings at the boundaries:
re.split(r"(\s+)", " foo\n") -> ['', ' ', 'foo', '\n', '']
The code was checking parts[0] and parts[-1] for whitespace, but those
are empty strings. The actual whitespace is at parts[1] and parts[-2].
Fix: drop empty strings at boundaries before processing, simplifying
the leading/trailing whitespace detection.
Prompt:
This change is