diff --git a/lib/util/settings.js b/lib/util/settings.js index 4f5c7769d..45d8ead79 100644 --- a/lib/util/settings.js +++ b/lib/util/settings.js @@ -312,6 +312,9 @@ function validate() { 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}')`); + if (name.includes('#') || name.includes('+')) { + throw new Error(`MQTT wildcard (+ and #) not allowed in friendly_name ('${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 8b14ffca0..0026e2b72 100644 --- a/test/settings.test.js +++ b/test/settings.test.js @@ -536,6 +536,18 @@ describe('Settings', () => { }).toThrowError(`Friendly name cannot end with a "/DIGIT" ('myname/123')`); }); + it('Configuration shouldnt be valid when friendly_name contains a MQTT wildcard', async () => { + write(configurationFile, { + devices: {'0x0017880104e45519': {friendly_name: 'myname#', retain: false}}, + }); + + settings._reRead(); + + expect(() => { + settings.validate(); + }).toThrowError(`MQTT wildcard (+ and #) not allowed in friendly_name ('myname#')`); + }); + it('Configuration shouldnt be valid when friendly_name is a postfix', async () => { write(configurationFile, { devices: {'0x0017880104e45519': {friendly_name: 'left', retain: false}},