← Back to Pull requests

Fix CRLF being counted as two line breaks with preserve_blank_lines #104

Closed
afonsojanu closed this pull request without merging on Oct 05, 2026 12:49 UTC
View on GitHub
afonsojanu afonsojanu commented on Sep 26, 2026 21:24 UTC
Author

Closes #103.

preserve_blank_lines=True splits the input on the character class [\r\n], which matches each of \r and \n separately. A Windows-style \r\n line ending is therefore split into two pieces with an empty string between them, and that empty string turns into an extra blank line once the pieces are joined back together with \n.

>>> titlecase("Line1\r\n\r\nLine2", preserve_blank_lines=True)
'Line1\n\n\n\nLine2'   # expected 'Line1\n\nLine2'

This changes the split to match a full line-ending sequence (\r\n, \r, or \n) instead of any single character in that class, so CRLF is treated as one line break like it should be. The preserve_blank_lines=False branch already used [\r\n]+ and doesn't have this problem, so it's untouched.

Added a test case covering CRLF and lone-CR input under preserve_blank_lines=True, since the existing blank-line tests only exercised \n.

Diff: 13 lines (+12 / -1) across 2 files Reviewer: alerque Review duration: 12445m
All Vouch review confidence checks passed
Residual risk 0.04 = Change Risk (0.20) × (1 − Review Confidence (0.81)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.20 · 13 lines diff across 2 files
0.20
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.71 · 2 substantive comment(s)
0.71
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
81%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.158
Real PR Conversation Timeline
5 items
alerque alerque approved these changes on Sep 29, 2026 09:33 UTC
Approved Reviewer

Approved these changes.

ppannuto ppannuto commented on code on Sep 30, 2026 17:33 UTC
Code Review
titlecase/tests.py:1
@@ -433,6 +433,17 @@ def test_complex_blanks(self):
         self.assertEqual(titlecase(s, preserve_blank_lines=True),
                 '\n\nLeading Blank\n\n\nMulti-Blank\n\n\n\n\nTrailing Blank\n\n')
 
+    def test_crlf_line_endings(self):
+        # A CRLF is a single line ending, not two, so it shouldn't introduce
+        # extra blank lines when preserve_blank_lines is on.
+        self.assertEqual(titlecase('a\r\nb', preserve_blank_lines=True), 'A\nB')

Ugh... line endings... :/

It seems like preserve should probably preserve blank lines from the input stream, i.e., not convert the line endings:

        self.assertEqual(titlecase('a\r\nb', preserve_blank_lines=True), 'A\r\nB')

Thoughts? I just maintain this as a convenience for people — honestly I don't even use the library anymore — so if you have a compelling use case one way or the other I'm open to it.

ppannuto ppannuto requested changes on Sep 30, 2026 17:33 UTC
Changes Requested Reviewer

Requested changes.

afonsojanu afonsojanu commented on Oct 05, 2026 12:49 UTC
Author

Part of a general cleanup on my end, closing this along with the rest of what I had open.

Reviewers
Assignees
afonsojanu afonsojanu
Labels
risk: low confidence: 81.1% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 20.2% (LOW) · Higher = larger blast radius
20.2%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 81.1% · Lower = rushed or shallow review
81.1%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 3.8% · Safe to merge
3.8%