Repository navigation
Readme: Convert CRLF line endings instead of deleting them - #917
Open
manishsongirkar wants to merge 1 commit into
Open
manishsongirkar wants to merge 1 commit into
manishsongirkar wants to merge 1 commit into
Conversation
CBT_Theme_Readme::sanitize() was added to avoid mixed DOS and Unix line endings in readme.txt. Its comment says it replaces DOS line endings with Unix ones, but it deleted every "\r\n" instead. Saving the theme metadata then joined all the lines of a readme.txt that used CRLF line endings, so the title and the header properties ended up on one line and the section titles ran into the text. Replace "\r\n" with "\n". The result has only Unix line endings, so the original problem stays fixed. Add tests that save a CRLF readme, a readme with mixed line endings, and credits that contain CRLF, and check that the lines stay apart and that no carriage return is left. Fixes WordPress#916
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.
Summary
CBT_Theme_Readme::sanitize()was added in #681 to avoid mixed DOS and Unix line endings inreadme.txt(#680). Its comment says it replaces DOS line endings with Unix line endings, but it deleted every\r\ninstead:rest_update_theme()reads the existingreadme.txt, passes it throughCBT_Theme_Readme::update()(which ends withsanitize()) and writes the result back. So saving the theme metadata from the editor joined all the lines of areadme.txtthat used CRLF line endings. The=== Theme ===title, the header properties and the section titles ended up on the same line, and the file was no longer a valid WordPress.org readme.Now
\r\nis replaced with\n. The lines stay apart, and the result still has only Unix line endings, so the problem from #680 stays fixed.Fixes #916
Changes
includes/create-theme/theme-readme.php:sanitize()replaces"\r\n"with"\n". This is a one-character change.tests/CbtThemeReadme/lineEndings.php(new): three tests that go through the publicupdate()method, becausesanitize()is private:\r\nkeeps one line per entry. Before this change the lines were joined with no separator (Font One - license AFont Two - license B).Test plan
npm run test:unit:php:base -- --filter CBT_ThemeReadme_LineEndings.--group readmepasses (16 tests).vendor/bin/phpcs --standard=phpcs.xml.diston the changed files is clean.readme.txtto CRLF line endings (282 lines).readme.txthad 18 lines and the header was joined (=== Twenty Twenty-Five ===Contributors: the WordPress team).\r, and the Fonts section is in the right place.Out of scope
\r(old Mac line ending) is not converted. The Theme Check plugin sometimes returns "Both DOS and UNIX style line endings" error #680 was about\r\n.add_or_update_prop()fails withUndefined array key 0when the readme has noRequires at leastorTested up toline. That is a separate bug, so I did not change it here.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code (Claude Sonnet 5.5)
Used for: Investigating the issue, implementing the fix, writing the tests, and drafting this description. I reproduced the bug in the editor, ran the tests, and reviewed and tested the change myself.