Skip to content
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

Add support for multiple space-separated CDATA sections in Magento\Framework\Xml\Parser #26822

Closed

Conversation

fnogatz
Copy link
Member

@fnogatz fnogatz commented Feb 11, 2020

Description (*)

Our XML files sometimes contain multiple CDATA sections per node. The XML parser class provided by Magento in /lib/internal/Magento/Framework/Xml/Parser.php already supports consecutive CDATA sections like <![CDATA[One]]><![CDATA[Two]]><![CDATA[Three]]>, which is correctly parsed as OneTwoThree. However this returns wrong results for empty text nodes in-between, like for <![CDATA[One]]> <![CDATA[Two]]> <![CDATA[Three]]>. This pull request adds the support and a related unit test.

Related Pull Requests

The switch statement has been added in #681.

Fixed Issues (if relevant)

No separate issue created.

Manual testing scenarios (*)

Unit tests added as part of this pull request.

You can use the current 2.3.4 version for testing. The file in question /lib/internal/Magento/Framework/Xml/Parser.php is unchanged since August 2017.

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

Resolved issues:

  1. resolves [Issue] Add support for multiple space-separated CDATA sections in Magento\Framework\Xml\Parser #29613: Add support for multiple space-separated CDATA sections in Magento\Framework\Xml\Parser

@m2-assistant
Copy link

m2-assistant bot commented Feb 11, 2020

Hi @fnogatz. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@sidolov sidolov added Priority: P3 May be fixed according to the position in the backlog. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Aug 17, 2020
@sidolov
Copy link
Contributor

sidolov commented Aug 17, 2020

@magento create issue

@ihor-sviziev ihor-sviziev force-pushed the xml-parser-multiple-cdata branch 2 times, most recently from 4330070 to ca07823 Compare September 7, 2020 10:35
@ihor-sviziev
Copy link
Contributor

@magento run all tests

@ihor-sviziev
Copy link
Contributor

@magento run Unit tests, Static Tests

@ihor-sviziev
Copy link
Contributor

@magento run Unit Tests

Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

Hi @fnogatz,
Thank you for updating your PR, now it looks really good.
The only thing left - could you please also fix failing static tests? I know that this failure not caused by your changes, but still need to have not failing static tests for changed files.

Thank you!

Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

✔ Approved.

Failing tests looks not related to changes form this PR.

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-8171 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

@fnogatz thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@ihor-sviziev
Copy link
Contributor

@magento run all tests

Copy link
Contributor

@engcom-Delta engcom-Delta left a comment

Choose a reason for hiding this comment

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

Hi @fnogatz . During testing PR changes I tried to add multiple CDATA sections into label and there are results:
Case 1: add multiple CDATA into comment node
image
Result:
❌ No comment is shown under field
image

Case 2: add multiple CDATA into label node
image
Result:
❌ Exception error "Notice: Array to string conversion in /var/www/html/magento2dev/lib/internal/Magento/Framework/Phrase.php on line 72 in log

Could you clarify in what cases multiple CDATA is used?

@fnogatz
Copy link
Member Author

fnogatz commented Oct 5, 2020

Hi @engcom-Delta. Thank you for having a look into it! We use the XML parser class provided by Magento in /lib/internal/Magento/Framework/Xml/Parser.php to process XML files not related to Magento, i.e. in a preprocessing step on our proprietary data-import. So the issue did not arise from a scenario where we tried to add multiple CDATA sections on Magento's files like config.xml, system.xml, widget.xml, or the like.

However, I tried to reproduce the issue on the Magento backend as you did by modifying Magento's XML files. To be honest, after two hours I have no clue why it behaves differently. Here's my Case 3:

  • Modify the description of cache_lifetime in magento/module-catalog-widget/etc/widget.xml to contain mixed CDATA and text, e.g., <![CDATA[ Some data]]> here<![CDATA[ <strong>html</strong> tags]]> are <![CDATA[<i>allowed</i> ]]>:
    Screenshot from 2020-10-05 14-23-34
  • Even without the modifications proposed in this PR, this gets correctly (!) displayed in the Magento backend:
    Screenshot from 2020-10-05 14-25-13
  • However, if I load this modified widget.xml programmatically and run xmlToArray(), it produces only the value string(16) "<i>allowed</i> ":
    $parser = new Parser();
    $parser->load('magento/module-catalog-widget/etc/widget.xml');
    $content = $parser->xmlToArray();    
    var_dump($content);
    /*
        ...
        ["_value"]=>
        array(2) {
          ["label"]=>
          array(2) {
            ["_value"]=>
            string(24) "Cache Lifetime (Seconds)"
            ["_attribute"]=>
            array(1) {
              ["translate"]=>
              string(4) "true"
            }
          }
          ["description"]=>
          array(2) {
            ["_value"]=>
            string(16) "<i>allowed</i>  "
            ["_attribute"]=>
            array(1) {
              ["translate"]=>
              string(4) "true"
            }
          }
        }
        ...
    */
    The expected string(64) " Some data here <strong>html</strong> tags are <i>allowed</i> " is returned only after applying this PR.

I have no idea, how the full description can be shown in the Magento backend without this PR, whereas manually loading the XML file results in an incomplete string at the same time -- which makes it hard for me to debug :/

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Oct 7, 2020

@engcom-Charlie @engcom-Delta @engcom-Bravo could you help with that?

@engcom-Charlie
Copy link
Contributor

@fnogatz you can see merged widget.xml files as array for example like this

$widgetReader = $om->create(\Magento\Widget\Model\Config\Reader::class);
$res = $widgetReader->read();
var_dump($res);

@engcom-Charlie
Copy link
Contributor

Hi, @fnogatz could you please provide steps to reproduce the issue?
Thank you.

@ihor-sviziev
Copy link
Contributor

Hi @fnogatz,
Could you check if the issue still reproducing? Could you add steps to reproduce?

@sidolov
Copy link
Contributor

sidolov commented Nov 11, 2020

@fnogatz I am closing this PR now due to inactivity.
Please reopen and update if you wish to continue.
Thank you for the collaboration!

@sidolov sidolov closed this Nov 11, 2020
@m2-assistant
Copy link

m2-assistant bot commented Nov 11, 2020

Hi @fnogatz, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix Award: test coverage Component: Xml help wanted Priority: P3 May be fixed according to the position in the backlog. Release Line: 2.4 Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Issue] Add support for multiple space-separated CDATA sections in Magento\Framework\Xml\Parser
6 participants