Restrict tags format

This commit is contained in:
Shweelan Samson authored and Zaid Abdulla committed 2019-06-05 00:17:36 -07:00
1 parent 83de65f913
commit 6c60ce6457
2 files changed
+18 -4

No files matched your search

+10 -3
View File
@@ -211,9 +211,16 @@ export function updateDeviceTags(deviceId, tags): Promise<void> {
const add = [];
const pull = [];
for (const [tag, onOff] of Object.entries(tags)) {
if (onOff) add.push(tag);
else pull.push(tag);
const regex = /^[0-9a-zA-Z_]+$/;
for (let [tag, onOff] of Object.entries(tags)) {
tag = tag.trim();
if (onOff) {
if (!tag.match(regex))
return void reject(new Error(`Invalid tag '${tag}'`));
add.push(tag);
} else {
pull.push(tag);
}
}
getClient()
.then(client => {