mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-28 20:55:39 +00:00
Bug 1452068 - Move MAX_TAG_LENGTH to the bookmarking API. r=Standard8
The tagging API is moving to the bookmarking API, this is one step Differential Revision: https://phabricator.services.mozilla.com/D2315 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
7596141cc9
commit
6da5d81859
@ -559,7 +559,7 @@ BookmarkImporter.prototype = {
|
||||
|
||||
if (tags) {
|
||||
bookmark.tags = tags.split(",").filter(aTag => aTag.length > 0 &&
|
||||
aTag.length <= Ci.nsITaggingService.MAX_TAG_LENGTH);
|
||||
aTag.length <= PlacesUtils.bookmarks.MAX_TAG_LENGTH);
|
||||
|
||||
// If we end up with none, then delete the property completely.
|
||||
if (!bookmark.tags.length) {
|
||||
|
@ -438,7 +438,7 @@ function translateTreeTypes(node) {
|
||||
if (node.tags) {
|
||||
// Separate any tags into an array, and ignore any that are too long.
|
||||
node.tags = node.tags.split(",").filter(aTag =>
|
||||
aTag.length > 0 && aTag.length <= Ci.nsITaggingService.MAX_TAG_LENGTH);
|
||||
aTag.length > 0 && aTag.length <= PlacesUtils.bookmarks.MAX_TAG_LENGTH);
|
||||
|
||||
// If we end up with none, then delete the property completely.
|
||||
if (!node.tags.length) {
|
||||
|
@ -123,6 +123,12 @@ var Bookmarks = Object.freeze({
|
||||
*/
|
||||
DEFAULT_INDEX: -1,
|
||||
|
||||
/**
|
||||
* Maximum length of a tag.
|
||||
* Any tag above this length is rejected.
|
||||
*/
|
||||
MAX_TAG_LENGTH: 100,
|
||||
|
||||
/**
|
||||
* Bookmark change source constants, passed as optional properties and
|
||||
* forwarded to observers. See nsINavBookmarksService.idl for an explanation.
|
||||
|
@ -267,7 +267,7 @@ const SYNC_BOOKMARK_VALIDATORS = Object.freeze({
|
||||
Object.values(PlacesSyncUtils.bookmarks.KINDS).includes(v)),
|
||||
query: simpleValidateFunc(v => v === null || (typeof v == "string" && v)),
|
||||
folder: simpleValidateFunc(v => typeof v == "string" && v &&
|
||||
v.length <= Ci.nsITaggingService.MAX_TAG_LENGTH),
|
||||
v.length <= PlacesUtils.bookmarks.MAX_TAG_LENGTH),
|
||||
tags: v => {
|
||||
if (v === null) {
|
||||
return [];
|
||||
@ -277,7 +277,7 @@ const SYNC_BOOKMARK_VALIDATORS = Object.freeze({
|
||||
}
|
||||
for (let tag of v) {
|
||||
if (typeof tag != "string" || !tag ||
|
||||
tag.length > Ci.nsITaggingService.MAX_TAG_LENGTH) {
|
||||
tag.length > PlacesUtils.bookmarks.MAX_TAG_LENGTH) {
|
||||
throw new Error(`Invalid tag: ${tag}`);
|
||||
}
|
||||
}
|
||||
|
@ -2800,7 +2800,7 @@ function validateTag(rawTag) {
|
||||
return null;
|
||||
}
|
||||
let tag = rawTag.trim();
|
||||
if (!tag || tag.length > Ci.nsITaggingService.MAX_TAG_LENGTH) {
|
||||
if (!tag || tag.length > PlacesUtils.bookmarks.MAX_TAG_LENGTH) {
|
||||
// Drop empty and oversized tags.
|
||||
return null;
|
||||
}
|
||||
|
@ -11,13 +11,6 @@ interface nsIVariant;
|
||||
[scriptable, uuid(9759bd0e-78e2-4421-9ed1-c676e1af3513)]
|
||||
interface nsITaggingService : nsISupports
|
||||
{
|
||||
|
||||
/**
|
||||
* Defines the maximal length of a tag. Related to the bug 407821
|
||||
* (https://bugzilla.mozilla.org/show_bug.cgi?id=407821)
|
||||
*/
|
||||
const unsigned long MAX_TAG_LENGTH = 100;
|
||||
|
||||
/**
|
||||
* Tags a URL with the given set of tags. Current tags set for the URL
|
||||
* persist. Tags in aTags which are already set for the given URL are
|
||||
|
@ -114,7 +114,7 @@ TaggingService.prototype = {
|
||||
// want to change it.
|
||||
tag.__defineGetter__("name", () => this._tagFolders[tag.id]);
|
||||
} else if (typeof(idOrName) == "string" && idOrName.length > 0 &&
|
||||
idOrName.length <= Ci.nsITaggingService.MAX_TAG_LENGTH) {
|
||||
idOrName.length <= PlacesUtils.bookmarks.MAX_TAG_LENGTH) {
|
||||
// This is a tag name.
|
||||
tag.name = trim ? idOrName.trim() : idOrName;
|
||||
// We can't know the id at this point, since a previous tag could
|
||||
|
@ -157,17 +157,15 @@ function run_test() {
|
||||
Assert.equal(ex.name, "NS_ERROR_ILLEGAL_VALUE");
|
||||
}
|
||||
|
||||
// Tag name length should be limited to nsITaggingService.MAX_TAG_LENGTH (bug407821)
|
||||
// Tag name length should be limited to PlacesUtils.bookmarks.MAX_TAG_LENGTH (bug407821)
|
||||
try {
|
||||
|
||||
// generate a long tag name. i.e. looooo...oong_tag
|
||||
var n = Ci.nsITaggingService.MAX_TAG_LENGTH;
|
||||
var n = PlacesUtils.bookmarks.MAX_TAG_LENGTH;
|
||||
var someOos = new Array(n).join("o");
|
||||
var longTagName = "l" + someOos + "ng_tag";
|
||||
|
||||
tagssvc.tagURI(uri1, ["short_tag", longTagName]);
|
||||
do_throw("Passing a bad tags array should throw");
|
||||
|
||||
} catch (ex) {
|
||||
Assert.equal(ex.name, "NS_ERROR_ILLEGAL_VALUE");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user