From 7def0b174f313b57e85ef1e3345715e8935270e3 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 3 Apr 2013 11:39:51 -0500 Subject: [PATCH] Bugfixes - Better YouTube URL parsing - Check for invalid regexes and report them - Channel names are no longer case-sensitive --- channel.js | 12 +++++++++--- user.js | 7 ++++++- www/assets/js/functions.js | 16 ++++++++++------ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/channel.js b/channel.js index 3fa8797f..059d8337 100644 --- a/channel.js +++ b/channel.js @@ -128,6 +128,11 @@ Channel.prototype.loadMysql = function() { Logger.syslog.log("Channel " + this.name + " is unregistered."); return; } + // [](/picard) I didn't realize that MySQL wasn't case sensitive. + // My bad. + else if(rows[0].name != this.name) { + this.name = rows[0].name; + } this.registered = true; // Load library @@ -674,12 +679,13 @@ Channel.prototype.unqueue = function(data) { pos: data.pos }); - if(data.pos < this.currentPosition) { - this.currentPosition--; - } if(data.pos == this.currentPosition) { this.currentPosition--; this.playNext(); + return; + } + if(data.pos < this.currentPosition) { + this.currentPosition--; } } diff --git a/user.js b/user.js index 07a8cf6a..3a8f2d2e 100644 --- a/user.js +++ b/user.js @@ -252,7 +252,12 @@ User.prototype.initCallbacks = function() { this.socket.on("chatFilter", function(data) { if(Rank.hasPermission(this, "chatFilter")) { if(data.cmd && data.cmd == "update" && this.channel != null) { - data.filter[0] = new RegExp(data.filter[0], "g"); + try { + data.filter[0] = new RegExp(data.filter[0], "g"); + } + catch(e) { + return; + } this.channel.updateFilter(data.filter); } else if(data.cmd && data.cmd == "remove" && this.channel != null) { diff --git a/www/assets/js/functions.js b/www/assets/js/functions.js index ed4cb0c8..93e02cc7 100644 --- a/www/assets/js/functions.js +++ b/www/assets/js/functions.js @@ -484,6 +484,7 @@ function removeCurrentPlayer(){ } function parseVideoURL(url){ + url = url.trim() if(typeof(url) != "string") return null; if(url.indexOf("youtu.be") != -1 || url.indexOf("youtube.com") != -1) { @@ -505,21 +506,18 @@ function parseVideoURL(url){ } function parseYTURL(url) { - url = url.replace("feature=player_embedded&", ""); - if(url.indexOf("&list=") != -1) - url = url.substring(0, url.indexOf("&list=")); - var m = url.match(/youtube\.com\/watch\?v=([^&]+)/); + var m = url.match(/v=([^&#]+)/); if(m) { // Extract ID return m[1]; } - var m = url.match(/youtu\.be\/([^&]+)/); + var m = url.match(/youtu\.be\/([^&#]+)/); if(m) { // Extract ID return m[1]; } // Final try - var m = url.match(/v=([^&]*)/); + var m = url.match(/([^&#]*)/); if(m) { // Extract ID return m[1]; @@ -727,6 +725,12 @@ function updateChatFilters(entries) { .appendTo($("").appendTo(newfilt)); var cback = (function(regex, replace) { return function() { if(regex.val() && replace.val()) { + try { + var dummy = new RegExp(regex.val(), "g"); + } + catch(e) { + alert("Invalid regex: " + e); + } socket.emit("chatFilter", { cmd: "update", filter: [regex.val(), replace.val(), true]