Skip to content

Readme: Convert CRLF line endings instead of deleting them - #917

Open
manishsongirkar wants to merge 1 commit into
WordPress:trunkfrom
manishsongirkar:fix/readme-crlf-line-endings
Open

manishsongirkar wants to merge 1 commit into
WordPress:trunkfrom
manishsongirkar:fix/readme-crlf-line-endings

Conversation

@manishsongirkar

Copy link
Copy Markdown

Summary

CBT_Theme_Readme::sanitize() was added in #681 to avoid mixed DOS and Unix line endings in readme.txt (#680). Its comment says it replaces DOS line endings with Unix line endings, but it deleted every \r\n instead:

$readme_content = str_replace( "\r\n", '', $readme_content );

rest_update_theme() reads the existing readme.txt, passes it through CBT_Theme_Readme::update() (which ends with sanitize()) and writes the result back. So saving the theme metadata from the editor joined all the lines of a readme.txt that 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\n is 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 public update() method, because sanitize() is private:
    • A readme with CRLF line endings keeps its header lines and its section titles on separate lines.
    • A readme with mixed line endings ends up with Unix line endings only.
    • Credits text that contains \r\n keeps one line per entry. Before this change the lines were joined with no separator (Font One - license AFont Two - license B).

Test plan

  • The new tests fail on trunk (all 3) and pass with this change: npm run test:unit:php:base -- --filter CBT_ThemeReadme_LineEndings.
  • --group readme passes (16 tests).
  • The full PHPUnit suite passes (276 tests, 3 multisite tests skipped in a single-site run).
  • vendor/bin/phpcs --standard=phpcs.xml.dist on the changed files is clean.
  • Manual test in the Site Editor with Twenty Twenty-Five:
    1. Change the theme's readme.txt to CRLF line endings (282 lines).
    2. Open Create Block Theme → Edit Theme Metadata, type three lines in Font credits and click Update.
    3. Before this change, readme.txt had 18 lines and the header was joined (=== Twenty Twenty-Five ===Contributors: the WordPress team).
    4. With this change, every line break is kept, the file has no \r, and the Fonts section is in the right place.

Out of scope

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.

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
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.

Readme: saving theme metadata joins all lines of a CRLF readme.txt together because sanitize() deletes "\r\n"

1 participant