-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Fix bug with utf-8 bug, change writePrompt to use one function prepareChoices #33911
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
Conversation
@@ -30,6 +30,7 @@ | |||
*/ | |||
class QuestionHelper extends Helper | |||
{ | |||
const DEFAULT_PROMPT = ' > '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be a public const ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, moved to Question class
b36d10b
to
cf9efe9
Compare
Please help, why 'TranslationFilesTest.php:42' is failing? |
Anyone? |
It doesn't seem related, don't worry about it. But perhaps you could get rid of it by rebasing on top of latest 3.4? |
0e1edd9
to
913f8c3
Compare
Rebased on top 3.4 |
913f8c3
to
b5e1596
Compare
Rebase on top 3.4, |
Are you serious? |
@proggga because of how Symfony releases new versions, October-November of each year is a very stressful moment for us. Moreover, every two years, the stress is even more intense because we release a new major version. This year is one of those years. So, we're ultra busy with millions of things and we may respond to you a bit late. Thanks for understanding! (and thanks for your contribution too!) |
Sorry for maybe being aggressive, It was strange, very fast people came and gave alot of changes, but after it disappeared |
There is a mismatch here: the PR title tells about a refacto, but the linked issue is about UTF-8 length computation. refacto go on master - fixes on 3.4. Could you please update the PR according to what it is? I didn't look better before asking :) |
Fixed |
{ | ||
$choices = $question->getChoices(); | ||
|
||
$maxWidth = max(array_map([$this, 'strlen'], array_keys($choices))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self::strlen
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[static::class, 'strlen']
(but honestly I've no issue with using $this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently use self::
everywhere, we don't expect those methods to be overidden.
$messages = []; | ||
|
||
foreach ($choices as $key => $value) { | ||
$width = $maxWidth - $this->strlen($key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self::strlen
foreach ($choices as $key => $value) { | ||
$width = $maxWidth - $this->strlen($key); | ||
// We using strlen + str_repeat to fix sprintf whitespace padding problem with UTF-8) | ||
$messages[] = sprintf(' [<%s>%s%s</%s>] %s', $tag, $key, str_repeat(' ', $width), $tag, $value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolas-grekas sprintf
left justify does not work with multibytes. Shouldn't we create a sprintf
method in the abstract Helper class like we did for strlen, substr, etc.? Or using str_repeat for all strings is ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, you want to implement sprintf in pure PHP.
Yes, sure... in theory :)
in practice, I don't know :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean add a sprintf helper method to handle the left justify. If the string is not utf-8 we use the normal sprintf. If it is, we use the str_repeat strategy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, sure!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@proggga Would you have time to take care of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for reviewing this,
Yea, Maybe I can, but I'm not true symphonist, so I don't know rules for creating new helper/naming/best place for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@proggga Would you have time to take care of this?
May be you can give instructions, and after may be I can do it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In your proposed changes, you replaces the sprintf left justify feat by strlen + str_repeat everytime. Firstly, this alternative should only be used for multibytes strings. Secondly, it should be done in a new helper method in the abstract Helper.php class (like we did for strlen and sbustr).
} | ||
$output->writeln($messages); | ||
// ChoiceQuestion can have any prompt | ||
$output->write($question->getPrompt() ?: Question::DEFAULT_PROMPT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getPrompt()
will always return a string. The constant is also useless. Just write the prompt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's another bug fixed by this PR btw. Unrelated to the linked issue.
// ChoiceQuestion can have any prompt | ||
$output->write($question->getPrompt() ?: Question::DEFAULT_PROMPT); | ||
} else { | ||
$output->write(Question::DEFAULT_PROMPT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here keep the old behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should actually move the prompt from the ChoiceQuestion to the Question class? 🤔
…n choices keys and custom prompt (fancyweb) This PR was merged into the 3.4 branch. Discussion ---------- [Console][SymfonyQuestionHelper] Handle multibytes question choices keys and custom prompt | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #33928 | License | MIT | Doc PR | - Replaces / finishes #33911 Commits ------- f175032 [Console][SymfonyQuestionHelper] Handle multibytes question choices keys and custom prompt
Refactor QuestionHelper and SymfonyQuestionHelper to use one function that prepare choices question. Remove duplicate code.