NaturalIntelligence / fast-xml-parser

Validate XML, Parse XML and Build XML rapidly without C/C++ based libraries and no callback.
https://naturalintelligence.github.io/fast-xml-parser/
MIT License
2.43k stars 297 forks source link

fix: validator bag when closing tag is not opened. #647

Closed RyosukeFukatani closed 3 months ago

RyosukeFukatani commented 3 months ago

Purpose / Goal

Fixes https://github.com/NaturalIntelligence/fast-xml-parser/issues/620

fxparser -V a.xml with input.xml.

</html>

On current master.

            if (tagName !== otg.tagName) {
                                ^

TypeError: Cannot read property 'tagName' of undefined
    at Object.exports.validate (/Users/ryosukefukatani/work/fast-xml-parser/src/validator.js:108:33)
    at callback (/Users/ryosukefukatani/work/fast-xml-parser/src/cli/cli.js:51:29)
    at /Users/ryosukefukatani/work/fast-xml-parser/src/cli/cli.js:78:9
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)

With this change.

{
  err: {
    code: 'InvalidTag',
    msg: "Closing tag 'html' has not been opened.",
    line: 1,
    col: 1
  }
}

Type

Please mention the type of PR

Note : Please ensure that you've read contribution guidelines before raising this PR. If your PR is in progress, please prepend [WIP] in PR title. Your PR will be reviewed when [WIP] will be removed from the PR title.

Bookmark this repository for further updates.

amitguptagwl commented 3 months ago

Thanks for your changes. Will wait until the PR is marked as WIP

RyosukeFukatani commented 3 months ago

@amitguptagwl Sorry, I found I should benchmark this PR, but I can't finish benchmark successfully. Could you help me?

I believe that this PR will make the benchmark hardly any worse.

ryosukefukatani@ryosukenoMacBook-Pro ~/w/fast-xml-parser (master) [1]> node  benchmark/XmlParser.js
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'benchmark'
Require stack:
- /Users/ryosukefukatani/work/fast-xml-parser/benchmark/XmlParser.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/ryosukefukatani/work/fast-xml-parser/benchmark/XmlParser.js:3:19)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/ryosukefukatani/work/fast-xml-parser/benchmark/XmlParser.js'
  ]
}
amitguptagwl commented 3 months ago

You can ignore benchmarking for this change :)

RyosukeFukatani commented 3 months ago

@amitguptagwl Thx! OK, WIP was removed.

amitguptagwl commented 3 months ago
Failures:
1) XML Validator should not validate xml with unexpected closing tag
  Message:
    Expected $.msg = 'Expected closing tag 'tag' (opened in line 1, col 11) instead of closing tag 'tag1'.' to equal 'Closing tag 'tag1' has not been opened.'.
  Stack:
    error properties: Object({ something: 'strange' })
    Error: Expected $.msg = 'Expected closing tag 'tag' (opened in line 1, col 11) instead of closing tag 'tag1'.' to equal 'Closing tag 'tag1' has not been opened.'.
        at <Jasmine>
        at validate (/home/runner/work/fast-xml-parser/fast-xml-parser/spec/validator_spec.js:4:234)
        at UserContext.<anonymous> (/home/runner/work/fast-xml-parser/fast-xml-parser/spec/validator_spec.js:4:5005)
        at <Jasmine>
RyosukeFukatani commented 3 months ago

@amitguptagwl Thx! I fixed test and checked test result locally.

coveralls commented 3 months ago

Coverage Status

coverage: 98.26% (+0.003%) from 98.257% when pulling b03c9681232aaa5ee7e8280c87ca4916045fec74 on RyosukeFukatani:fix/not_opened_tag into 3ab1b3b7a51e56a2fbf4fdf209b855d5449f2445 on NaturalIntelligence:master.