Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FrameworkBundle] Convert null prefix to an empty string in translation:update#20184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@chalasr
Copy link
Member

QA
Branch?2.7
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#20044
LicenseMIT
Doc PRn/a

This command needs the ability to use an empty string as prefix, which is not possible usingbin/console translation:update --prefix="" because$argv doesn't parse empty strings thus the value is converted tonull byArgvInput (only since#19946, before the option was not considered to be set, giving the default'__' thus this should be fine from a BC pov).

Here I propose to explicitly convert theprefix value to an empty string if set tonull, as it is a very specific need and we can't guess that fromArgvInput.
An other way to fix it could be to add a--no-prefix option to the command but I don't think it is worth it, and it couldn't be treated as a bug fix thus not fixed before3.2.

$output->text('Parsing templates');
$extractor =$this->getContainer()->get('translation.extractor');
$extractor->setPrefix($input->getOption('prefix'));
$extractor->setPrefix($input->getOption('prefix') ?:'');
Copy link
Member

Choose a reason for hiding this comment

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

You should be explicit here:null === $input->getOption('prefix') ? '' : $input->getOption('prefix'). If not, a prefix with a falsy value like0 is converted to an empty string, which is not what we want.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Fixed

@chalasrchalasrforce-pushed theframework/trans-upd_command_noprefix branch from141e679 tof02b687CompareOctober 9, 2016 11:14
@fabpot
Copy link
Member

Thank you@chalasr.

@fabpotfabpot merged commitf02b687 intosymfony:2.7Oct 9, 2016
fabpot added a commit that referenced this pull requestOct 9, 2016
…n translation:update (chalasr)This PR was merged into the 2.7 branch.Discussion----------[FrameworkBundle] Convert null prefix to an empty string in translation:update| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#20044| License       | MIT| Doc PR        | n/aThis command needs the ability to use an empty string as prefix, which is not possible using `bin/console translation:update --prefix=""` because `$argv` doesn't parse empty strings thus the value is converted to `null` by `ArgvInput` (only since#19946, before the option was not considered to be set, giving the default `'__'` thus this should be fine from a BC pov).Here I propose to explicitly convert the `prefix` value to an empty string if set to `null`, as it is a very specific need and we can't guess that from `ArgvInput`.An other way to fix it could be to add a `--no-prefix` option to the command but I don't think it is worth it, and it couldn't be treated as a bug fix thus not fixed before `3.2`.Commits-------f02b687 [FrameworkBundle] Convert null prefix to an empty string in translation:update command
@chalasrchalasr deleted the framework/trans-upd_command_noprefix branchOctober 9, 2016 11:33
This was referencedOct 27, 2016
// load any messages from templates
$extractedCatalogue =newMessageCatalogue($input->getArgument('locale'));
$output->text('Parsing templates');
$prefix =$input->getOption('prefix');
Copy link

@navitronicnavitronicOct 27, 2016
edited
Loading

Choose a reason for hiding this comment

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

Maybe I am misunderstanding this, but$prefix can never be assigned with anull value here. If it were null, shouldn't it return the default value of__ specified on L40?

Which would mean that the following ternary never returns an empty string.

Copy link
MemberAuthor

@chalasrchalasrNov 6, 2016
edited
Loading

Choose a reason for hiding this comment

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

Unfortunately, you're right.

In fact the issue is actually quite complex, the current implementation makes impossible to detectt if an option has been set with an empty string, it'salways parsed as null, so it's impossible get an empty value for an option withVALUE_OPTIONALand a default value, because if it isnull, the default value is used (the case without default value has been fixed in#19946). We would need to differentiate if an option has been set without any value or with an empty value ("") and I don't think we should make this difference as it would be really hard to do it backward compatible, some use cases would be broken for having this one working (empty strings are converted to null, it is the expected behavior and it is tested).

chalasr added a commit to chalasr/symfony that referenced this pull requestNov 7, 2016
… empty string in translation:update (chalasr)"This reverts commit3f650f8, reversingchanges made to962248d.
fabpot added a commit that referenced this pull requestNov 7, 2016
… to an empty string in translation:update (chalasr)" (chalasr)This PR was merged into the 2.7 branch.Discussion----------Revert "bug#20184 [FrameworkBundle] Convert null prefix to an empty string in translation:update (chalasr)"| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#20184 (comment)| License       | MIT| Doc PR        | n/aThis reverts commit3f650f8 because the fix is not valid.It is actually not possible to have an option with value optional given empty to be `empty` if this one has a default value. The default value will always be the one returned, see#20184 (comment) for details.Commits-------b2fa7c4 Revert "bug#20184 [FrameworkBundle] Convert null prefix to an empty string in translation:update (chalasr)"
fabpot added a commit that referenced this pull requestNov 7, 2016
* 2.7:  prefer getSourceContext() over getSource()  [HttpFoundation] Avoid implicit null to array conversion in request matcher  Revert "bug#20184 [FrameworkBundle] Convert null prefix to an empty string in translation:update (chalasr)"  Update UPGRADE-2.7.md
fabpot added a commit that referenced this pull requestNov 7, 2016
* 2.8:  prefer getSourceContext() over getSource()  [HttpFoundation] Avoid implicit null to array conversion in request matcher  Revert "bug#20184 [FrameworkBundle] Convert null prefix to an empty string in translation:update (chalasr)"  Update UPGRADE-2.7.md
fabpot added a commit that referenced this pull requestNov 7, 2016
* 3.1:  prefer getSourceContext() over getSource()  [HttpFoundation] Avoid implicit null to array conversion in request matcher  Revert "bug#20184 [FrameworkBundle] Convert null prefix to an empty string in translation:update (chalasr)"  Update UPGRADE-2.7.md
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

+1 more reviewer

@navitronicnavitronicnavitronic left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@chalasr@fabpot@navitronic@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp