Added client-side protection against long tags
This commit is contained in:
parent
47260bd5fa
commit
e58b556f66
2 changed files with 17 additions and 7 deletions
2
TODO
2
TODO
|
@ -111,8 +111,6 @@ miscellaneous:
|
||||||
- endless pager should include information about page number
|
- endless pager should include information about page number
|
||||||
- add hotkeys for focusing items in top navigation
|
- add hotkeys for focusing items in top navigation
|
||||||
- add ability to select tags text in tag input
|
- add ability to select tags text in tag input
|
||||||
- pasting tags should have protection against very long clipboard content
|
|
||||||
- add protection against ridiculously long tag names
|
|
||||||
- add customizable favicon
|
- add customizable favicon
|
||||||
- add customizable logo
|
- add customizable logo
|
||||||
- add log engine and log everything that should be logged
|
- add log engine and log everything that should be logged
|
||||||
|
|
|
@ -67,15 +67,17 @@ App.Controls.TagInput = function(
|
||||||
} else {
|
} else {
|
||||||
pastedText = (e.originalEvent || e).clipboardData.getData('text/plain');
|
pastedText = (e.originalEvent || e).clipboardData.getData('text/plain');
|
||||||
}
|
}
|
||||||
pasteText(pastedText);
|
|
||||||
});
|
|
||||||
|
|
||||||
function pasteText(pastedText) {
|
if (pastedText.length > 200) {
|
||||||
|
window.alert('Pasted text is too long.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var pastedTags = pastedText.split(/\s+/);
|
var pastedTags = pastedText.split(/\s+/);
|
||||||
var lastTag = pastedTags.pop();
|
var lastTag = pastedTags.pop();
|
||||||
_.map(pastedTags, addTag);
|
_.map(pastedTags, addTag);
|
||||||
$input.val(lastTag);
|
$input.val(lastTag);
|
||||||
}
|
});
|
||||||
|
|
||||||
$input.unbind('keydown').bind('keydown', function(e) {
|
$input.unbind('keydown').bind('keydown', function(e) {
|
||||||
if (_.contains(inputConfirmKeys, e.which) && !$input.val()) {
|
if (_.contains(inputConfirmKeys, e.which) && !$input.val()) {
|
||||||
|
@ -86,8 +88,8 @@ App.Controls.TagInput = function(
|
||||||
} else if (_.contains(tagConfirmKeys, e.which)) {
|
} else if (_.contains(tagConfirmKeys, e.which)) {
|
||||||
var tag = $input.val();
|
var tag = $input.val();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
addTag(tag);
|
|
||||||
$input.val('');
|
$input.val('');
|
||||||
|
addTag(tag);
|
||||||
} else if (e.which === KEY_BACKSPACE && jQuery(this).val().length === 0) {
|
} else if (e.which === KEY_BACKSPACE && jQuery(this).val().length === 0) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
removeLastTag();
|
removeLastTag();
|
||||||
|
@ -99,6 +101,16 @@ App.Controls.TagInput = function(
|
||||||
if (tag.length === 0) {
|
if (tag.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tag.length > 64) {
|
||||||
|
//showing alert inside keydown event leads to mysterious behaviors
|
||||||
|
//in some browsers, hence the timeout
|
||||||
|
window.setTimeout(function() {
|
||||||
|
window.alert('Tag is too long.');
|
||||||
|
}, 10);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var oldTags = getTags();
|
var oldTags = getTags();
|
||||||
if (_.contains(_.map(oldTags, function(tag) { return tag.toLowerCase(); }), tag.toLowerCase())) {
|
if (_.contains(_.map(oldTags, function(tag) { return tag.toLowerCase(); }), tag.toLowerCase())) {
|
||||||
flashTag(tag);
|
flashTag(tag);
|
||||||
|
|
Loading…
Reference in a new issue