Browse Source

feat(BulkActions): Regex validation of items

Owen Diffey 3 years ago
parent
commit
0814cc9f59

+ 7 - 2
frontend/src/components/modals/BulkActions.vue

@@ -100,9 +100,14 @@ export default {
 	methods: {
 		addItem() {
 			if (!this.itemInput) return;
-			if (!this.items.includes(this.itemInput))
+			if (this.type.regex && !this.type.regex.test(this.itemInput)) {
+				new Toast(`Invalid ${this.type.name} format.`);
+			} else if (this.items.includes(this.itemInput)) {
+				new Toast(`Duplicate ${this.type.name} specified.`);
+			} else {
 				this.items.push(this.itemInput);
-			this.itemInput = null;
+				this.itemInput = null;
+			}
 		},
 		removeItem(index) {
 			this.items.splice(index, 1);

+ 8 - 3
frontend/src/pages/Admin/tabs/Songs.vue

@@ -715,7 +715,10 @@ export default {
 			this.bulkActionsType = {
 				name: "tags",
 				action: "songs.editTags",
-				items: selectedRows.map(row => row._id)
+				items: selectedRows.map(row => row._id),
+				regex: new RegExp(
+					/^[a-zA-Z0-9_]{1,64}$|^[a-zA-Z0-9_]{1,64}\[[a-zA-Z0-9_]{1,64}\]$/
+				)
 			};
 			this.openModal("bulkActions");
 		},
@@ -723,7 +726,8 @@ export default {
 			this.bulkActionsType = {
 				name: "artists",
 				action: "songs.editArtists",
-				items: selectedRows.map(row => row._id)
+				items: selectedRows.map(row => row._id),
+				regex: new RegExp(/^(?=.{1,64}$).*$/)
 			};
 			this.openModal("bulkActions");
 		},
@@ -731,7 +735,8 @@ export default {
 			this.bulkActionsType = {
 				name: "genres",
 				action: "songs.editGenres",
-				items: selectedRows.map(row => row._id)
+				items: selectedRows.map(row => row._id),
+				regex: new RegExp(/^[\x00-\x7F]{1,32}$/)
 			};
 			this.openModal("bulkActions");
 		},