From 35b97ec0fe57c3bbb9c58f56452548ee6252c352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Sa=C5=A1ek?= Date: Wed, 9 Sep 2020 14:42:18 +0200 Subject: [PATCH] Add validation for SSID with diacritic --- src/common/WiFiSettings/WiFiSettings.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/common/WiFiSettings/WiFiSettings.js b/src/common/WiFiSettings/WiFiSettings.js index a16d8d7..8b55fa5 100644 --- a/src/common/WiFiSettings/WiFiSettings.js +++ b/src/common/WiFiSettings/WiFiSettings.js @@ -63,6 +63,16 @@ function prepDataToSubmit(formData) { return formData; } +function diacriticValidation(string) { + for (let i = 0; i < string.length; i++) { + const charCode = string.charCodeAt(i); + if (charCode < 32 || charCode > 127) { + return false; + } + } + return true; +} + export function validator(formData) { const formErrors = formData.devices.map((device) => { if (!device.enabled) return {}; @@ -71,6 +81,10 @@ export function validator(formData) { if (device.SSID.length > 32) errors.SSID = _("SSID can't be longer than 32 symbols"); if (device.SSID.length === 0) errors.SSID = _("SSID can't be empty"); + if (!diacriticValidation(device.SSID)) + errors.SSID = _( + "Your SSID contains non-standard characters. These are not forbidden, but could cause problems on some devices." + ); if (device.password.length < 8) errors.password = _("Password must contain at least 8 symbols");