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

Printing fails after outgoing a return value, and the content of the value is missing #126

Open
3 tasks
baobao9999 opened this issue Jan 18, 2024 · 0 comments

Comments

@baobao9999
Copy link

Description:

After calling this method, the array of XMLElement is obtained, and it can be printed normally in the current method, but after the return value is obtained, when the getElements method is called, an error will be reported when arr is printed

Fuzi/Node.swift:122: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
Fuzi/Node.swift:122: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

ele.attr("href") === ""

ele.stringValue == ""

private func getResult(_ xPath: String) -> Array {
let node : Fuzi.HTMLDocument = htmlNode

        let nodeset = node.xpath(xPath)
             
         let array = nodeset.map { $0 }
            
         return array

}

public func getElements(_ xPath: String) -> Array<XMLElement>? {
    if xPath.isEmpty { return [] }
    do {
        var jxNodes = Array<XMLElement>()
        let ruleAnalyzes = RuleAnalyzer(xPath)
        let rules = try ruleAnalyzes.splitRule("&&", "||", "%%")
        
        if (rules.count == 1) {
            
            
            if let arr = getResult(rules[0]){
                
                return arr
            }}
        
    }
}
  • Expected behaviour:
  • test 1
    ele.attr("href") === "/test1.html"

ele.stringValue == "test 1"

  • Actual behaviour:

Fuzi/Node.swift:122: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
Fuzi/Node.swift:122: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

ele.attr("href") === ""

ele.stringValue == ""

Environment

  • Package Manager:

    • Carthage, version:
    • CocoaPods, version:
    • Manually
  • Fuzi version:3.1.3

  • Xcode version:15.0.1

How to reproduce:

xpath

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

1 participant