Skip to content

Comments

Fix trailing newline loss when scrubbing sensitive lines#229

Merged
dhalperi merged 1 commit intomasterfrom
spr/master/c8455062
Feb 5, 2026
Merged

Fix trailing newline loss when scrubbing sensitive lines#229
dhalperi merged 1 commit intomasterfrom
spr/master/c8455062

Conversation

@dhalperi
Copy link
Member

@dhalperi dhalperi commented 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.

This change is Reviewable

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 dhalperi enabled auto-merge (squash) February 5, 2026 20:05
Copy link
Member Author

@dhalperi dhalperi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhalperi reviewed 2 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved.

@dhalperi dhalperi merged commit c41e155 into master Feb 5, 2026
12 checks passed
@dhalperi dhalperi deleted the spr/master/c8455062 branch February 5, 2026 20:05
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant