keymap-editor icon indicating copy to clipboard operation
keymap-editor copied to clipboard

Restrict accepted characters for devicetree identifiers

Open nickcoutsos opened this issue 2 years ago • 2 comments

There is some code in the backend that will strip out certain characters in things like layer names, but this should really happen on the frontend for transparency.

  1. Review the devicetree spec
  2. Update EditableField to accept a validator prop, and display errors(?)
  3. Ensure sanitization is being applied consistently in the API
  4. Define validation schema for the next API version

nickcoutsos avatar Jul 01 '22 02:07 nickcoutsos

This may also need to restrict use of known identifiers. Example:

https://github.com/NickNyxson/Corne/commit/29fd21280464f8c0de91f3c1222bd8243a90a06b#diff-b61dda8e54e3077ceff51199e79bc432344beb397417a8fed25154aad22607fbR96

devicetree error: /__w/Corne/Corne/config/corne.keymap:96 (column 9): parse error: expected node name, property name, or '}'

Note that F1 is a defined keycode for the F1 key, and is likely getting evaluated to the constant value by the preprocessor, and therefore not a valid node name.

nickcoutsos avatar Jul 01 '22 04:07 nickcoutsos

I've added validation to the editable identifier/label in the combo and macro editors, and also added an additional check that the given identifier doesn't match any preprocessor defines -- either keyboard specific like layer aliases (e.g. #define BASE 0) or from ZMK's list of key codes. For completeness this should include the list of behaviour "commands" (e.g. BT_SEL, RGB_TOG, EP_OFF, etc.). I'm not sure how useful this is in practice but it's a fairly trivial addition.

nickcoutsos avatar Jul 07 '22 13:07 nickcoutsos

Finally implemented warnings to check that name/label/reference values in the keymap don't conflict with eachother or with pre-defined ZMK identifiers.

nickcoutsos avatar Mar 07 '23 01:03 nickcoutsos