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

Init doesn't fail for invalid XML #57

Open
djbe opened this issue Apr 24, 2017 · 1 comment
Open

Init doesn't fail for invalid XML #57

djbe opened this issue Apr 24, 2017 · 1 comment

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.

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

No branches or pull requests

2 participants