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

Parser must skip unopened closing tags #577

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

varad11
Copy link

@varad11 varad11 commented May 22, 2023

Purpose / Goal

When an xml/html has closing tags without opening tags, then the parser should skip it and continue it's parsing rather than blocking execution by throwing exception.

Code

new XMLParser({ ignoreAttributes: false })
.parse('<rootNode>
<parentTag attr='my attr 1'>
    <childTag>Hello</childTag>
</parentTag>
<parentTag attr='my attr 2'>
    </childTag> <!--Unopned Closing Tag-->
    </childTag> <!--Unopned Closing Tag-->
</parentTag>
</parentTag> <!--Unopned Closing Tag-->
<parentTag attr='my attr 3'>
    <childTag>World</childTag>
</parentTag>
</rootNode>')

Output

Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'addChild')

Expected Output

{
    "rootNode": {
        "parentTag": [
            {
                "childTag": "Hello",
                "@_attr": "my attr 1"
            },
            {
                "@_attr": "my attr 2"
            },
            {
                "childTag": "World",
                "@_attr": "my attr 3"
            }
        ]
    }
}

Benchmark

Before Changes

Running Suite: XML Parser benchmark
fxp v3 : 84779.33893486593 requests/second
fxp : 51112.199678104116 requests/second
fxp - preserve order : 50404.274179940876 requests/second       
xmlbuilder2 : 19283.905598973546 requests/second
xml2js  : 13955.238383909073 requests/second

After Changes

Running Suite: XML Parser benchmark
fxp v3 : 78604.65479491939 requests/second
fxp : 47949.98355614185 requests/second
fxp - preserve order : 51482.93159290693 requests/second
xmlbuilder2 : 20161.459509073473 requests/second
xml2js  : 14325.551131080862 requests/second

Type

Please mention the type of PR

  • Bug Fix
  • Refactoring / Technology upgrade
  • New Feature

@varad11 varad11 changed the title Parse unopened closing tags Parser must skip unopened closing tags May 23, 2023
@amitguptagwl
Copy link
Member

Thanks for the PR. But the merge can be delayed due to major change in the library are in progress. As a part of new development, there is a plan to introduce strict property. If it is false then warning will be issued but the parsing will continue.

And this is not the bug fix bu a feature :)

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

Successfully merging this pull request may close these issues.

2 participants