netbox-device-view
netbox-device-view copied to clipboard
Enhancement: Add input sanitization to Grid Template Area form field
Problem:
The grid-template-areas CSS property is highly sensitive to syntax, including the exact types of whitespace characters used as separators within the quoted row strings. When manually pasting layout definitions into the "Grid template area" field in the NetBox UI (e.g., from documentation, examples, or other sources), non-standard whitespace characters (such as Non-Breaking Spaces - NBSP, U+00A0) can be inadvertently introduced. These characters look identical to regular spaces in a standard text field, as presented in the Netbox UI but are invalid as separators in grid-template-areas. This invalidates the CSS definition, causing the layout to break (e.g., ports failing to position correctly and piling up), and these hidden characters are very difficult for users to spot and remove manually.
Justification for Change:
Implementing automated sanitization for this form field on save would prevent hard-to-debug layout issues caused by invisible characters and reduce the need for users to employ external tools to clean text before pasting it into NetBox.
Proposed Solution:
Add a cleaning method to the Django form responsible for the DeviceView model (in forms.py). This method should specifically target the grid_template_area field (clean_grid_template_area).
The cleaning method should process the submitted string value to replace common non-standard whitespace characters with standard spaces (U+0020). Replacing Non-Breaking Spaces (\u00A0) is a key step, as they are a frequent source of this issue. Additional sanitization could include standardizing multiple consecutive whitespace characters into a single space or stripping leading/trailing whitespace, although the primary focus is replacing the hidden invalid characters.