From 4d54e5038b280f88b60fc4d2103cde6d4c7f0a2d Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sat, 7 Mar 2020 23:06:22 +0100 Subject: [PATCH] Refuse to start when friendly_name ends with /DIGIT. #2645 --- lib/util/settings.js | 1 + test/settings.test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/util/settings.js b/lib/util/settings.js index d408a25d68..0285847a71 100644 --- a/lib/util/settings.js +++ b/lib/util/settings.js @@ -307,6 +307,7 @@ function validate() { const check = (name) => { if (names.includes(name)) throw new Error(`Duplicate friendly_name '${name}' found`); if (postfixes.includes(name)) throw new Error(`Following friendly_name are not allowed: '${postfixes}'`); + if (name.match(/.*\/\d*$/)) throw new Error(`Friendly name cannot end with a "/DIGIT" ('${name}')`); names.push(name); }; Object.values(_settingsWithDefaults.devices).forEach((d) => check(d.friendly_name)); diff --git a/test/settings.test.js b/test/settings.test.js index da36f613f5..b96a9b7066 100644 --- a/test/settings.test.js +++ b/test/settings.test.js @@ -512,6 +512,18 @@ describe('Settings', () => { }).toThrowError(`Duplicate friendly_name 'myname' found`); }); + it('Configuration shouldnt be valid when friendly_name ends with /DIGIT', async () => { + write(configurationFile, { + devices: {'0x0017880104e45519': {friendly_name: 'myname/123', retain: false}}, + }); + + settings._reRead(); + + expect(() => { + settings.validate(); + }).toThrowError(`Friendly name cannot end with a "/DIGIT" ('myname/123')`); + }); + it('Configuration shouldnt be valid when friendly_name is a postfix', async () => { write(configurationFile, { devices: {'0x0017880104e45519': {friendly_name: 'left', retain: false}},