clj-commons/etaoin

Calling `etaoin.impl.xpath/expand` with an unknown `:fn/*` function doesn't throw an exception

Closed this issue · 0 comments

dgr commented

Version
1.1.41

Platform
All

Symptom
Today, the query map syntax supports a number of "functions," identified using :fn/* keywords, that expand into specific, helpful XPath constructs. The (Clojure) function that performs this expansion to XPath is etaoin.impl.xpath/expand. Today, if you supply expand with an unknown "function," say :fn/unknown, it doesn't throw an exception, but silently converts such a function to a search for an element with an attribute named unknown.

For example:

user> (xpath/expand {:fn/has-text "some test"})  ;; known "function" - OK
".//*[contains(text(), \"some test\")]"
user> (xpath/expand {:unknown-attr :value})   ;; random attribute - OK
".//*[@unknown-attr=\"value\"]"
user> (xpath/expand {:fn/unknown-attr :value}) ;; random unknown "function" - should throw
".//*[@unknown-attr=\"value\"]"

Actual behavior
Just silently accepts the unknown :fn/* keyword, strips off the fn namespace, and uses it like it would any other keyword specifying an attribute to search for.

Expected behavior
When supplied with an unknown function keyword, expand should throw an error and identify the keyword. If this is not done, simple typos can be very difficult to debug because they are silently converted to queries for attributes.

Diagnosis
The etaoin.impl.xpath/expand function doesn't check for unknown function keywords.

Action
I'll submit a PR.