javarosa icon indicating copy to clipboard operation
javarosa copied to clipboard

null = nodeName

Open MartijnR opened this issue 6 years ago • 2 comments

You may not like reading this (likely a historical artefact).... ;)

Apparently this works in Collect as a check to see whether name1 has a value:

not(${name1} = null)

That is really quite wrong.

What I think should happen is that the XPath evaluator should look for the node <null> that is a child of the evaluation context and compares the string value of that node (if it exists) with the string value of <name1>.

You can test how null is treated in a browser developer console:

  1. document.evaluate('null', document.querySelector('body'), null, 3).booleanValue returns false (<body> has no child element <null>)

  2. now create <null> element as a child of <body>: document.querySelector('body').appendChild(document.createElement('null'))

  3. and now the same evaluation as in 1, returns true! (regardless of whether the null element has a value which is correct and according to the boolean() spec).

So tl/dr; there is no concept of null in XPath.

MartijnR avatar Jun 13 '18 22:06 MartijnR

Very interesting! I'm curious to know how you've come across this quirk. Did someone stumble onto it?

lognaturel avatar Jun 14 '18 00:06 lognaturel

Yes, someone was using this and wondered why it wasn't working in Enketo. (I advised to replace null with ""). First, I was surprised to see it didn't throw an Exception (in the browser XPath evaluator) and then realized it's just treated like a path to a node.

MartijnR avatar Jun 14 '18 15:06 MartijnR