Repository navigation
fix: narrow the language code rule to what escapes the directory - #9
Merged
Merged
Conversation
The strict [A-Za-z0-9_-] rule broke valid codes such as sr@latin, zh.Hant and
türkçe. setDefault() and change() now reject only what can leave the language
directory or select its parent: an empty code, "/", "\", a NUL byte, and codes
made only of dots and spaces ("." ".." and the forms Windows normalises to
them). Everything else loads as it did in 2.0.0.
In directory mode the path is also escaped before it reaches glob(), so a
directory literally named like a wildcard (".*") cannot match ".." and pull in
the parent's PHP files.
Translator: reject ":" on Windows (not a valid file name character there),
assert the "language code is invalid" message in the rejection tests so a
missing-file error cannot pass for them, and cover every glob escape ("*",
"?", "[") with a literal wildcard-named directory. The changelog now says that
codes pointing into a sub-directory (sub/en) are rejected, and the exception
table shows the current message.
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
[A-Za-z0-9_-]rule from fix: reject language codes outside [A-Za-z0-9_-] #7 rejected valid codes such assr@latin,zh.Hantandtürkçe.setDefault()/change()now throwTranslatorExceptiononly for an empty code,/,\, a NUL byte, or a code made only of dots and spaces (.,..,...,..,. .). Every other code works as in 2.0.0.glob(), so a directory literally named.*no longer matches..and loads the parent's PHP files.:/ wrapper-like names; docs andCHANGELOG.md(Unreleased) updated.Why the path cannot escape
The identifier is appended to the developer's
setDir()path as one component. Without a separator it cannot add a component;./..(and their Windows-normalised forms) are the only single components that select the directory itself or its parent. A drive letter (C:), a stream-wrapper prefix (phar:,php:) or\\?\only has meaning at the start of a path, and that start is the developer's directory.:mid-path can only address an alternate data stream of a file inside the language directory.Test plan
vendor/bin/phpunit(142 tests; 85 of them fail against 2.0.0's source: the rejections and the glob case)vendor/bin/phpstan analyse,vendor/bin/php-cs-fixer fix --dry-run --diff,composer validate --strict,wiki-sync.sh --check docs