Skip to content

[Console] Fix Windows code page support #41113

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
May 7, 2021
Merged

Conversation

orkan
Copy link
Contributor

@orkan orkan commented May 5, 2021

Q A
Branch? 5.2
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #37385, Fix #35842, Fix #36324, Fix #37495, Fix #37278
License MIT

Corrects previous fixes that dealt with the mojibake problem on Windows where an OEM code page was applied to an input string and then messed with PHP.internal_encoding setting used by the script. This caused strings with different encodings to be displayed on the console output.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 5.x branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@chalasr
Copy link
Member

chalasr commented May 6, 2021

Thanks for the PR.
This should target the 4.4 branch as the logic is the same there. Can you rebase and change the PR base branch accordingly?

@chalasr chalasr added this to the 4.4 milestone May 6, 2021
@orkan
Copy link
Contributor Author

orkan commented May 6, 2021

Well, at first I was thinking the same as the PR guide says all bug fixes should adress 4.4 branch, but here I'm fixing a method that was introduced later in 352aed3

@chalasr
Copy link
Member

chalasr commented May 6, 2021

Ok got it, yet this patch changes somethig that exists on 4.4:

if (\function_exists('sapi_windows_cp_set')) {
// Codepage used by cmd.exe on Windows to allow special characters (éàüñ).
@sapi_windows_cp_set(1252);
}
.
So I guess we need an equivalent PR for 4.4. It'd be great if you could submit one. Otherwise, no worries, someone else will do (maybe me).

Also, can you fix the CS issues reported by fabbot (see failing CI builds)?

@orkan
Copy link
Contributor Author

orkan commented May 6, 2021

I think this is beyond my knowledge of git, but applying this fix against 4.4 will result in conflicts with 352aed3 changes... An equivalent would be to not change anything ;)

Btw, I fixed CS issues but why fabbot wants me to remove these lines?

      *
      * @param int    $cp Code page in IBM/EBCDIC format
      * @param string $in User input
-     *
-     * @return string
      */
     private function resetIOCodepage(int $cp, string $in): string
     {

@Nyholm
Copy link
Member

Nyholm commented May 6, 2021

If Fabbot suggest to do CS fix on a unrelated line, you should just ignore it.

@orkan
Copy link
Contributor Author

orkan commented May 6, 2021

It's actually related but where's the problem? Should I add description to the returned string?

@chalasr
Copy link
Member

chalasr commented May 6, 2021

Symfony omits some annotations (@return, @param) when they don't provide more value that type declarations already provide.
Here @return string states something already known thanks to the string return type, so the patch can be applied :)

@chalasr chalasr modified the milestones: 4.4, 5.2 May 6, 2021
@orkan
Copy link
Contributor Author

orkan commented May 6, 2021

OK. Got it! Thanks

@nicolas-grekas nicolas-grekas changed the title [Console] Add Windows code page support [Console] Fix Windows code page support May 7, 2021
@nicolas-grekas nicolas-grekas changed the base branch from 5.x to 5.2 May 7, 2021 14:24
@nicolas-grekas
Copy link
Member

Thank you @orkan.

@nicolas-grekas nicolas-grekas merged commit 53e47b3 into symfony:5.2 May 7, 2021
@fabpot fabpot mentioned this pull request May 9, 2021
nicolas-grekas added a commit that referenced this pull request May 11, 2021
This PR was submitted for the 5.x branch but it was merged into the 5.2 branch instead.

Discussion
----------

[Console] Fix Windows code page support

My previous PR #41113 was corrected by `@nicolas`-grekas on 3bac7fe. He introduced logical changes in the code which resulted in incorrect behaviour.
The basic idea was to restore the I/O codepage as soon as you get console input. And you have to do this even if `fgets()` returns **false**, because otherwise you'll leave the changed codepage for the rest of the script execution - and that's bad!

Commits
-------

044b585 [Console] Fix Windows code page support
@nicolas-grekas
Copy link
Member

PR for 4.4 welcome btw!

@Nyholm
Copy link
Member

Nyholm commented May 11, 2021

Great work @orkan. Thank you and congratulations to your first contribution.

As Nicolas says, could you do a similar PR to the 4.4 branch? Robin said the bug exists there to but the logic has been moved around.

@orkan
Copy link
Contributor Author

orkan commented May 11, 2021

Hi @Nyholm.
Can you describe me please, what's the workflow here? I can see from the git history, that 4.4 is regulary merged into 5.2, right? So, if I remove something in 5.2 that existed in 4.4 and later introduce it again as a PR for 4.4, doesn't it mean it'll show up in 5.2 too?
That's the thing here. I don't want my fix for 4.4 to show up in 5.2... They'll be incompatible!

@Nyholm
Copy link
Member

Nyholm commented May 12, 2021

Of course.

Normally, bug fixes are merged in 4.4 (or the lowest branch they exists in). Every few days we merge 4.4 -> 5.2 -> 5.x.

later introduce it again as a PR for 4.4

I dont understand. We should create a PR to 4.4 to add setIOCodepage and resetIOCodepage, right?

They'll be incompatible!

Could you elaborate how they are incompatible? I dont really understand.

@fabpot fabpot mentioned this pull request May 12, 2021
@orkan
Copy link
Contributor Author

orkan commented May 13, 2021

Ok. Nevermind. I pushed fix #41210 for 4.4. "I am going to sit back now and..." see what will be the result code after 4.4 > 5.2

@nicolas-grekas
Copy link
Member

Resolving merge conflicts is our maintainer's duty. This one was easy ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants