XLSForm / pyxform

A Python package to create XForms for ODK Collect.
BSD 2-Clause "Simplified" License
80 stars 136 forks source link

461: Add value and label params to select_.._from_file #577

Closed lindsay-stevens closed 2 years ago

lindsay-stevens commented 2 years ago

Closes #461

Why is this the best possible solution? Were any other approaches considered?

ODK Validate rejects certain characters for the value and label parameters. Presumably the ref value is placed into a XPath, and characters that are XPath operators cause a problem. The error from ODK Validate looks like the below.

>> Something broke the parser. See above for a hint.
org.javarosa.xpath.XPathException: XPath evaluation: Parse error in XPath path: [val*].
Bad node: org.javarosa.xpath.parser.ast.ASTNodeAbstractExpr@63e2203c

Since this isn't super clear, the parameter values are validated by pyxform with the regex ^[a-zA-Z_][a-zA-Z0-9\-_\.]*$. The error message is similar to other design issues, e.g.

[row : 2] Parameter 'value' has a value which is not valid. Values must begin with a letter or underscore. Subsequent characters can include letters, numbers, dashes, underscores, and periods.

What are the regression risks?

None are anticipated.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

Before submitting this PR, please make sure you have:

lognaturel commented 2 years ago

I've updated Validate manually to https://github.com/getodk/validate/releases/tag/v1.17.0 and run nosetests without the new test erroring.

~so I think it should work. I'm not as confident as I'd like to be because I wasn't able to run the automatic Validate update script (something has changed there?) and I'm having trouble running tests in my IDE.~

With a clear head I fixed my environment and was able to both run the Validate update script and run tests from my IDE. Hopefully you can do the update in a commit here and then move forward, @lindsay-stevens.

lognaturel commented 2 years ago

I've taken a first look through and this looks great to me and thoroughly tested. I'll take a deeper dive asap. @MartijnR perhaps you'll be interested in a peek as well? I think you were particularly interested in this change at some point.

MartijnR commented 2 years ago

Thanks! Very cool! I played around converting some forms and wasn't able to break it.