Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Init doesn't fail for invalid XML #57

Open
djbe opened this issue Apr 24, 2017 · 2 comments · May be fixed by #128
Open

Init doesn't fail for invalid XML #57

djbe opened this issue Apr 24, 2017 · 2 comments · May be fixed by #128

Comments

@djbe
Copy link

djbe commented Apr 24, 2017

Description:

  • Expected behaviour:
    Reading a broken XML throws an error.
  • Actual behaviour:
    Fuzi recovers and parses the XML partially (up to the error).

Environment

  • Package Manager: CocoaPods
  • Fuzi version: 1.0.1
  • Xcode version: 8.3.2

How to reproduce:

While unit testing our library, we want to catch that our parser fails on invalid documents. Instead, the broken file gets partially parsed, because Fuzi sets the option to ignore errors (XML_PARSE_NOERROR): https://github.com/cezheng/Fuzi/blob/master/Sources/Document.swift#L112

As the initializers are failable, as a user we'd expect it to fail for invalid documents. Now, I can understand that not all users might want this, but could it be made available as an option? For example, modify the initialisers to accept an extra options parameter, by default set to

Int32(XML_PARSE_NOWARNING.rawValue | XML_PARSE_NOERROR.rawValue | XML_PARSE_RECOVER.rawValue)

Even better would be to provide a swift OptionSet that maps to the libxml values.

Example faulty XML:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <>
  <color name="ArticleTitle">#33fe66</color>
</resources>
@cezheng
Copy link
Owner

cezheng commented Jan 29, 2018

I think I'm fine with adding an option for parsing. I'll be happy to review any PRs.

@BPerlakiH BPerlakiH linked a pull request Jul 12, 2024 that will close this issue
@BPerlakiH
Copy link

@cezheng please check:
#128

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

Successfully merging a pull request may close this issue.

3 participants