Skip to content

[Console] Fixes "Incorrectly nested style tag found" error when using multi-line header content #46114

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 14, 2022
Merged

[Console] Fixes "Incorrectly nested style tag found" error when using multi-line header content #46114

merged 1 commit into from
May 14, 2022

Conversation

Perturbatio
Copy link
Contributor

@Perturbatio Perturbatio commented Apr 19, 2022

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
License MIT

This is intended to fix a bug identified as a result of usage in a separate package (hotmeteor/spectator#69 and hotmeteor/spectator#90).

When a multi-line string is provided in the headers the Table helper produces content that cannot be rendered correctly.

in src/Symfony/Component/Console/Helper/Table.php there's a line $lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell)) the exact line version varies between package versions, but this hasn't changed since 2017.

What this seems to do when you pass a multi line terminal string is wrap the newlines in a default style tag, presumably to try to force a reset.

But what happens in the headers is that it splits it so that each line after the first starts with the close tag and ends with the open, resulting in the incorrect nesting error. All this does is shift the newline character to after the reset style tag. A side-effect of this is that it appears to now pad out the content of the compact and borderless styles in a manner which (to me) appears to be the intended output i.e. spaces padded out to the full table width.

@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 6.1 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

@stof stof changed the base branch from 6.0 to 6.1 April 19, 2022 15:25
@Perturbatio Perturbatio changed the base branch from 6.1 to 6.0 April 19, 2022 15:26
@stof
Copy link
Member

stof commented Apr 19, 2022

I changed the target branch to 6.1 as that's what your branch is currently based on, allowing to have a clean diff.

The expected target of the bugfix (which will require rebasing the git branch, not only editing the PR metadata) is either 4.4 or 5.4 (depending on whether 4.4 is affected, which is probably the case as you said that this code hasn't changed since 2017). But there is no chance that the lowest affected version is 6.0

@stof stof changed the base branch from 6.0 to 6.1 April 19, 2022 15:29
@Perturbatio
Copy link
Contributor Author

I changed the target branch to 6.1 as that's what your branch is currently based on, allowing to have a clean diff.

The expected target of the bugfix (which will require rebasing the git branch, not only editing the PR metadata) is either 4.4 or 5.4 (depending on whether 4.4 is affected, which is probably the case as you said that this code hasn't changed since 2017). But there is no chance that the lowest affected version is 6.0

Yeah, I think I'm misunderstanding where to branch from , It's not difficult to create a patch for this since it's such a tiny change. Is there a branch I should be creating this from to PR into?

@stof
Copy link
Member

stof commented Apr 19, 2022

@Perturbatio if the lowest affected maintained version is 4.4 (which is likely the case for this bug), the fix needs to be applied to 4.4. The easiest for that is to create your branch directly from the 4.4 branch. But you can still change that after the fact with a rebase. See https://symfony.com/doc/current/contributing/code/pull_requests.html#rebase-your-pull-request (be careful about the last step requiring a force push, not a merge of the upstream feature branch, which is a common mistake done when following that doc not carefully)

@Perturbatio Perturbatio changed the base branch from 6.1 to 4.4 April 19, 2022 17:10
@Perturbatio
Copy link
Contributor Author

Perturbatio commented Apr 20, 2022

@stof The current set of failing tests (TextDescriptorTest) pass locally, but in GitHub (only in
PHPUnit / Tests (8.1, low-deps) (pull_request) ), they don't seem to have any expected value. Is there something that might prevent the tests from reading data from the fixtures for this specific test run?

@Perturbatio Perturbatio requested a review from stof April 22, 2022 08:41
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Please revert all unrelated CS changes, so that the PR is focused on one topic.

@lyrixx lyrixx removed their request for review May 10, 2022 12:23
@nicolas-grekas nicolas-grekas changed the title Fixes "Incorrectly nested style tag found" error when using multi-line… Fixes "Incorrectly nested style tag found" error when using multi-line header content May 14, 2022
@nicolas-grekas nicolas-grekas modified the milestones: 6.0, 4.4 May 14, 2022
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

(I reverted the not-needed CS changes)

@carsonbot carsonbot changed the title Fixes "Incorrectly nested style tag found" error when using multi-line header content [Console] Fixes "Incorrectly nested style tag found" error when using multi-line header content May 14, 2022
@nicolas-grekas
Copy link
Member

Thank you @Perturbatio.

@nicolas-grekas nicolas-grekas merged commit 265d58a into symfony:4.4 May 14, 2022
@fabpot fabpot mentioned this pull request May 14, 2022
@Perturbatio Perturbatio deleted the fix-multiline-headers-in-console-table branch May 17, 2022 08:27
This was referenced May 27, 2022
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