Fixed: Error when entering unsupported character in tag

This commit is contained in:
Mark McDowall 2015-01-21 23:31:45 -08:00
parent 313e48be61
commit 90056044bc
2 changed files with 17 additions and 4 deletions

View File

@ -100,6 +100,7 @@ namespace NzbDrone.Core.Test.ParserTests
//[TestCase("Sex And The City S6E15 - Catch-38 [RavyDavy].avi", "Sex And The City", 6, 15)] // -38 is getting treated as abs number //[TestCase("Sex And The City S6E15 - Catch-38 [RavyDavy].avi", "Sex And The City", 6, 15)] // -38 is getting treated as abs number
[TestCase("Castle.2009.S06E03.720p.HDTV.X264-DIMENSION [PublicHD].mkv", "Castle.2009", 6, 3)] [TestCase("Castle.2009.S06E03.720p.HDTV.X264-DIMENSION [PublicHD].mkv", "Castle.2009", 6, 3)]
[TestCase("19-2.2014.S02E01.720p.HDTV.x264-CROOKS", "19-2 2014", 2, 1)] [TestCase("19-2.2014.S02E01.720p.HDTV.x264-CROOKS", "19-2 2014", 2, 1)]
[TestCase("Hulk and the Agents of SMASH S02E08 1080p WEB-DL DD5 1 H 264-YFN", "Hulk and the Agents of S.M.A.S.H.", 2, 8)]
//[TestCase("", "", 0, 0)] //[TestCase("", "", 0, 0)]
public void should_parse_single_episode(string postTitle, string title, int seasonNumber, int episodeNumber) public void should_parse_single_episode(string postTitle, string title, int seasonNumber, int episodeNumber)
{ {

View File

@ -14,11 +14,12 @@ define(
$.fn.tagsinput.Constructor.prototype.add = function (item, dontPushVal) { $.fn.tagsinput.Constructor.prototype.add = function (item, dontPushVal) {
var self = this; var self = this;
var tagLimitations = new RegExp('[^-_a-z0-9]', 'i');
if (typeof item === 'string' && this.options.tag) { if (typeof item === 'string' && this.options.tag) {
if (item === null || item === '' || tagLimitations.test(item)) { var test = testTag(item);
if (item === null || item === '' || !testTag(item)) {
return; return;
} }
@ -133,10 +134,10 @@ define(
var substringMatcher = function() { var substringMatcher = function() {
return function findMatches(q, cb) { return function findMatches(q, cb) {
// regex used to determine if a string contains the substring `q` // regex used to determine if a string contains the substring `q`
var substrRegex = new RegExp(q, 'i'); //var substrRegex = new RegExp(q, 'i');
var matches = _.select(TagCollection.toJSON(), function (tag) { var matches = _.select(TagCollection.toJSON(), function (tag) {
return substrRegex.test(tag.label); return tag.label.toLowerCase().indexOf(q.toLowerCase()) > -1;
}); });
cb(matches); cb(matches);
@ -148,4 +149,15 @@ define(
return _.contains(tagValues, tag.id); return _.contains(tagValues, tag.id);
}); });
}; };
var testTag = function(item) {
var tagLimitations = new RegExp('[^-_a-z0-9]', 'i');
try {
return !tagLimitations.test(item);
}
catch (e) {
return false;
}
};
}); });