Skip to content

Commit

Permalink
Refuse to start when friendly_name ends with /DIGIT. #2645
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Mar 7, 2020
1 parent 407d329 commit 4d54e50
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/util/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
12 changes: 12 additions & 0 deletions test/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
Expand Down

0 comments on commit 4d54e50

Please sign in to comment.