guardian / typerighter

Even if you’re the right typer, couldn’t hurt to use Typerighter!
Apache License 2.0
276 stars 12 forks source link

Validate patterns for regex and xml rules #406

Closed jonathonherbert closed 1 year ago

jonathonherbert commented 1 year ago

What does this change?

Adds validation for regex and LTXML rules. It's surfaced under the field. The validation errors themselves can be rather obscure, but I've tried to make it clear that they're related to the syntax of the pattern.

It all happens server-side.

Also links the validator errors for categories.

regex xml
Screenshot 2023-08-11 at 13 59 50 Screenshot 2023-08-11 at 13 59 59

How to test

Create a rule, and then enter an invalid regex (for example, an unterminated pair of parentheses), or invalid xml (for example, an unterminated tag, or no tag at all!) for regex and languagetool rules respectively. You should get the appropriate error messages

rhystmills commented 1 year ago

I think the CategorySelector in the RuleFormBatchEdit component also needs to be provided with validationErrors.

jonathonherbert commented 1 year ago

Thanks for spotting! Ooh, batch editing publication validation. I won't address that in this PR (it's not addressed at all IIUC), but it's a good reminder that the validation story for that will need to be different. ab6e7143687b35e6d5560e9c41b54b36de9a058c fixes.

samanthagottlieb commented 1 year ago

Forgot to mention that CI is still failing - seemingly because RuleManagerSpec.scala isn't formatted properly

jonathonherbert commented 1 year ago

Thanks @samanthagottlieb! Good spot, I'd forgotten to push my latest changes.