keymap-editor
keymap-editor copied to clipboard
Restrict accepted characters for devicetree identifiers
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.
- Review the devicetree spec
- Update
EditableField
to accept a validator prop, and display errors(?) - Ensure sanitization is being applied consistently in the API
- Define validation schema for the next API version
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.
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.
Finally implemented warnings to check that name/label/reference values in the keymap don't conflict with eachother or with pre-defined ZMK identifiers.