Skip to content

Normalize text domain string in make-json command - #498

Merged
swissspidy merged 1 commit into
mainfrom
fix/domain-header
Aug 3, 2026
Merged

swissspidy merged 1 commit into
mainfrom
fix/domain-header

Conversation

@swissspidy

@swissspidy swissspidy commented Aug 3, 2026 •

Copy link
Copy Markdown
Member

Applying some slight hardening

Summary by CodeRabbit

  • Bug Fixes
    • Improved safety when generating JSON filenames from translation domains.
    • Domain values from headers and command-line options are now normalized to safe filenames, preventing directory traversal issues.

Copilot AI review requested due to automatic review settings August 3, 2026 08:08
@swissspidy
swissspidy requested a review from a team as a code owner August 3, 2026 08:08
@swissspidy swissspidy added the command:i18n-make-json Related to 'i18n make-json' command label Aug 3, 2026
@swissspidy swissspidy added this to the 2.7.4 milestone Aug 3, 2026
@codecov

codecov Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 43645048-942b-4ca5-b4d8-7c202948bd88

📥 Commits

Reviewing files that changed from the base of the PR and between 81f6fcf and 851f7d0.

📒 Files selected for processing (2)
  • features/makejson.feature
  • src/MakeJsonCommand.php

📝 Walkthrough

Walkthrough

The JSON generation command now removes unsafe characters from effective translation domains before creating filenames. End-to-end coverage verifies domains from PO headers and CLI arguments produce files within the destination directory.

Changes

Domain filename sanitization

Layer / File(s) Summary
Normalize domains before JSON filename creation
src/MakeJsonCommand.php, features/makejson.feature
make_json() removes characters other than letters, digits, and hyphens from the effective domain. End-to-end scenarios verify normalized filenames for PO-header and CLI-provided domains.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: normalizing the text domain string in the make-json command.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/domain-header

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the wp i18n make-json command by ensuring the text domain used in output JSON filenames is normalized to a safe character set, preventing domains sourced from PO headers or CLI args from producing unsafe/undesired paths.

Changes:

  • Sanitize the effective $domain in MakeJsonCommand::make_json() by stripping non-alphanumeric / non-hyphen characters before it is used to prefix the output base filename.
  • Add a Behat scenario that verifies normalization for both the X-Domain PO header and the --domain CLI argument, including asserting no file is created outside the intended destination directory.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/MakeJsonCommand.php Normalizes/sanitizes the domain string before using it in the JSON output base filename.
features/makejson.feature Adds acceptance coverage ensuring unsafe domains from headers/flags are normalized and do not escape the destination path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@swissspidy
swissspidy merged commit 787ac68 into main Aug 3, 2026
78 of 79 checks passed
@swissspidy
swissspidy deleted the fix/domain-header branch August 3, 2026 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:i18n-make-json Related to 'i18n make-json' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants