Fix several bugs due to line endings not properly handled on Windows platform#216
Fix several bugs due to line endings not properly handled on Windows platform#216MapleCCC wants to merge 1 commit intothlorenz:masterfrom
Conversation
… which causes insidious bug like thlorenz#161
AndrewSouthpaw
left a comment
There was a problem hiding this comment.
Thanks for the contribution, and sorry for the slow reply!
I worry a little about this being the default behavior always. Perhaps there are Windows users out there who already have this problem solved. Or that as a Windows user perhaps they're still using the regular \r in their editors.
So my impression right now is that it isn't safe to turn on for everyone.
If you wanted, you could create a flag to enable the behavior, something like --useCRLFEndings or something. Then people could opt into it if that's their desired line endings.
| return homeExpanded.replace(/\s/g, '\\ '); | ||
| } | ||
|
|
||
| function readFile(path, encoding) { |
There was a problem hiding this comment.
I think a name like xFileWithCRLFHandling would be more self-documenting.
There was a problem hiding this comment.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no suggestions.
Comments skipped due to low confidence (4)
doctoc.js:20
- [nitpick] The function name 'readFile' is generic. Consider renaming it to 'readFileWithLineEndingConversion' for clarity.
function readFile(path, encoding) {
doctoc.js:32
- [nitpick] The function name 'writeFile' is generic. Consider renaming it to 'writeFileWithLineEndingConversion' for clarity.
function writeFile(path, data, encoding) {
doctoc.js:20
- Ensure that the new behavior of converting line endings in 'readFile' is covered by tests.
function readFile(path, encoding) {
doctoc.js:32
- Ensure that the new behavior of converting line endings in 'writeFile' is covered by tests.
function writeFile(path, data, encoding) {
In a nut shell, this PR fixes several bugs:
Fix the bug that files on Windows always get modified by doctoc even when nothing has changed, and ultimately leading to non-usability of doctoc as pre-commit hook, elaborated on issue Unusable as 'pre-commit' hook, since it will always fail. #161.
Fix the bug that files on Windows, after modified by doctoc, inadvertently get undesirable mixed line endings.
Fix the bug that files on Windows with a TOC that has no title, are inferred by doctoc to has a TOC title that contains a single character "\r", which ultimately leads to extra line breaks.
Close #161.