diff --git a/package.json b/package.json
index d4e22b11..31aa1a1f 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"author": "Calvin Montgomery",
"name": "CyTube",
"description": "Online media synchronizer and chat",
- "version": "3.52.2",
+ "version": "3.52.3",
"repository": {
"url": "http://github.com/calzoneman/sync"
},
diff --git a/src/channel/playlist.js b/src/channel/playlist.js
index 09d1f114..e8dca412 100644
--- a/src/channel/playlist.js
+++ b/src/channel/playlist.js
@@ -1218,6 +1218,12 @@ PlaylistModule.prototype.clean = function (test) {
* == Command Handlers ==
*/
+/*
+ * TODO: investigate how many people are relying on regex
+ * capabilities for /clean. Might be user friendlier to
+ * replace it with a glob matcher (or at least remove the
+ * -flags)
+ */
function generateTargetRegex(target) {
const flagsre = /^(-[img]+\s+)/i
var m = target.match(flagsre);
@@ -1242,7 +1248,15 @@ PlaylistModule.prototype.handleClean = function (user, msg, meta) {
"/cleantitle
"
});
}
- var target = generateTargetRegex(args.join(" "));
+ var target;
+ try {
+ target = generateTargetRegex(args.join(" "));
+ } catch (error) {
+ user.socket.emit("errorMsg", {
+ msg: `Invalid target: ${args.join(" ")}`
+ });
+ return;
+ }
this.channel.logger.log("[playlist] " + user.getName() + " used " + cmd +
" with target regex: " + target);
diff --git a/test/channel/playlist.js b/test/channel/playlist.js
new file mode 100644
index 00000000..12d383ea
--- /dev/null
+++ b/test/channel/playlist.js
@@ -0,0 +1,53 @@
+const PlaylistModule = require('../../lib/channel/playlist');
+const assert = require('assert');
+const Config = require('../../lib/config');
+
+describe('PlaylistModule', () => {
+ describe('#handleClean', () => {
+ let fakeChannel = {
+ uniqueName: 'testChannel',
+ logger: {
+ log() {
+
+ }
+ },
+ broadcastToRoom() {
+ },
+ broadcastAll() {
+ },
+ modules: {
+ permissions: {
+ canDeleteVideo() {
+ return true;
+ }
+ }
+ }
+ };
+ let fakeUser = {
+ getName() {
+ return 'testUser';
+ },
+ socket: {
+ emit() {
+ }
+ }
+ };
+ let playlistModule = new PlaylistModule(fakeChannel);
+
+ it('rejects invalid regexes', () => {
+ let sentError = false;
+
+ fakeUser.socket.emit = (event, payload) => {
+ assert.strictEqual(event, 'errorMsg');
+ assert.deepStrictEqual(payload, {
+ msg: "Invalid target: -i * -m"
+ });
+ sentError = true;
+ };
+
+ playlistModule.handleClean(fakeUser, "/clean -i * -m", {});
+
+ assert(sentError, 'Expected error due to invalid regex');
+ });
+ });
+});