Repository navigation
fix: reject language codes outside [A-Za-z0-9_-] - #7
Merged
Merged
Conversation
setDefault() and change() joined the identifier into the path of a file that was require'd, so a request-supplied value such as ../config/install could run PHP files outside the language directory. Both now throw a TranslatorException before any file is touched and leave the state unchanged. The docs and the changelog describe the new behaviour.
setDefault() and change() assigned the active/default language before loading
the pack, so change('xx') left xx active after the exception. They now load
first. In directory mode a language is cached only after all its files have
loaded, so a broken file no longer leaves a half-loaded language that a later
call accepts silently. The interface docblocks list the invalid-code case.
2 tasks done
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
setDefault()andchange()now throwTranslatorExceptionfor an empty identifier or one containing anything other than letters, digits,_and-(matched with\A...\z, so a trailing newline is rejected too).required, so../config/installcould run PHP files outside the language directory.docs/(API reference, Exceptions, Quick Start, Recipes) andCHANGELOG.mddescribe the new behaviour.Compatibility
Codes such as
en,en_USandpt-BRkeep working. A language pack whose name uses.or/must be renamed. No public signature changes.Test plan
vendor/bin/phpunit(95 tests; the 50 new ones fail without the fix)vendor/bin/phpstan analysevendor/bin/php-cs-fixer fix --dry-run --diffcomposer validate --strictwiki-sync.sh --check docs