Skip to content

[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2016

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Oct 8, 2016

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/a

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

@@ -119,7 +119,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
$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 like 0 is converted to an empty string, which is not what we want.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@chalasr chalasr force-pushed the framework/trans-upd_command_noprefix branch from 141e679 to f02b687 Compare October 9, 2016 11:14
@fabpot
Copy link
Member

fabpot commented Oct 9, 2016

Thank you @chalasr.

@fabpot fabpot merged commit f02b687 into symfony:2.7 Oct 9, 2016
fabpot added a commit that referenced this pull request Oct 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/a

This 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
@chalasr chalasr deleted the framework/trans-upd_command_noprefix branch October 9, 2016 11:33
This was referenced Oct 27, 2016
@@ -118,8 +118,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
// load any messages from templates
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
$output->text('Parsing templates');
$prefix = $input->getOption('prefix');
Copy link

@navitronic navitronic Oct 27, 2016

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 a null 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
Member Author

@chalasr chalasr Nov 6, 2016

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's always parsed as null, so it's impossible get an empty value for an option with VALUE_OPTIONAL and a default value, because if it is null, 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 request Nov 7, 2016
… empty string in translation:update (chalasr)"

This reverts commit 3f650f8, reversing
changes made to 962248d.
fabpot added a commit that referenced this pull request Nov 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/a

This reverts commit 3f650f8 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 request Nov 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 request Nov 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 request Nov 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 free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants