Improve CRLF handling in the decoder#20
Open
smortezah wants to merge 3 commits intotoon-format:mainfrom
Open
Conversation
Contributor
|
Hi @smortezah, |
There was a problem hiding this comment.
Pull Request Overview
This PR enhances cross-platform compatibility by normalizing different line ending formats (CRLF, CR, LF) to a consistent LF format before parsing, preventing issues with files created on different operating systems.
Key Changes:
- Added line ending normalization logic in the scanner to handle Windows (CRLF) and old Mac (CR) formats
- Implemented comprehensive test coverage for CRLF/CR handling in both scanner and decoder
- Ensured escaped sequences in quoted strings are preserved during normalization
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/toon_format/_scanner.py | Added line ending normalization logic to convert CRLF and CR to LF |
| tests/test_scanner.py | Added TestCRLFHandling class with tests for various line ending scenarios |
| tests/test_decoder.py | Added TestCRLFDecoding class to verify decoder handles different line endings correctly |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bpradana
previously approved these changes
Nov 9, 2025
bpradana
left a comment
There was a problem hiding this comment.
approved despite CI failed on lint
🚀🚀🚀
Updating comments for specificity of replacing characters Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Justar96
approved these changes
Nov 9, 2025
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.
This pull request improves cross-platform compatibility in the
toon_formatscanner and decoder by normalizing different line endings (Windows CRLF and old Mac CR) to LF, ensuring consistent parsing behavior regardless of the source file's origin. It also adds comprehensive tests to verify correct handling of various line ending scenarios.Line ending normalization:
src/toon_format/_scanner.pyto normalize Windows CRLF (\r\n) and old Mac CR (\r) line endings to LF (\n) before parsing, preventing stray carriage return characters from appearing in parsed content.Test coverage improvements:
TestCRLFDecodingintests/test_decoder.pyto verify that the decoder correctly handles CRLF, CR, mixed line endings, and quoted strings containing escaped\rand\nsequences, including strict mode decoding.TestCRLFHandlingintests/test_scanner.pyto ensure the scanner normalizes all types of line endings, preserves indentation, and works correctly in strict mode.