Bug 997030 - Don't encodeURI twice in bookmarks.html. r=mano

This commit is contained in:
Marco Bonardo 2014-05-20 22:52:48 +02:00
parent 57bb73df1c
commit ebdf84621f
4 changed files with 52 additions and 4 deletions

View File

@ -113,6 +113,14 @@ function escapeHtmlEntities(aText) {
.replace("'", "'", "g");
}
/**
* Provides URL escaping for use in HTML attributes of the bookmarks file,
* compatible with the old bookmarks system.
*/
function escapeUrl(aText) {
return (aText || "").replace("\"", "%22", "g");
}
function notifyObservers(aTopic, aInitialImport) {
Services.obs.notifyObservers(null, aTopic, aInitialImport ? "html-initial"
: "html");
@ -1087,10 +1095,10 @@ BookmarkExporter.prototype = {
_writeLivemark: function (aItem, aIndent) {
this._write(aIndent + "<DT><A");
let feedSpec = aItem.annos.find(anno => anno.name == PlacesUtils.LMANNO_FEEDURI).value;
this._writeAttribute("FEEDURL", encodeURI(feedSpec));
this._writeAttribute("FEEDURL", escapeUrl(feedSpec));
let siteSpecAnno = aItem.annos.find(anno => anno.name == PlacesUtils.LMANNO_SITEURI);
if (siteSpecAnno)
this._writeAttribute("HREF", encodeURI(siteSpecAnno.value));
this._writeAttribute("HREF", escapeUrl(siteSpecAnno.value));
this._writeLine(">" + escapeHtmlEntities(aItem.title) + "</A>");
this._writeDescription(aItem, aIndent);
},
@ -1109,7 +1117,7 @@ BookmarkExporter.prototype = {
}
this._write(aIndent + "<DT><A");
this._writeAttribute("HREF", encodeURI(aItem.uri));
this._writeAttribute("HREF", escapeUrl(aItem.uri));
this._writeDateAttributes(aItem);
yield this._writeFaviconAttribute(aItem);
@ -1152,7 +1160,7 @@ BookmarkExporter.prototype = {
return;
}
this._writeAttribute("ICON_URI", encodeURI(favicon.uri.spec));
this._writeAttribute("ICON_URI", escapeUrl(favicon.uri.spec));
if (!favicon.uri.schemeIs("chrome") && favicon.dataLen > 0) {
let faviconContents = "data:image/png;base64," +

View File

@ -0,0 +1,37 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Checks that we don't encodeURI twice when creating bookmarks.html.
*/
function run_test() {
run_next_test();
}
add_task(function() {
let uri = NetUtil.newURI("http://bt.ktxp.com/search.php?keyword=%E5%A6%84%E6%83%B3%E5%AD%A6%E7%94%9F%E4%BC%9A");
let bm = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
uri,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark");
let file = OS.Path.join(OS.Constants.Path.profileDir, "bookmarks.exported.997030.html");
if ((yield OS.File.exists(file))) {
yield OS.File.remove(file);
}
yield BookmarkHTMLUtils.exportToFile(file);
// Remove the bookmarks, then restore the backup.
PlacesUtils.bookmarks.removeItem(bm);
yield BookmarkHTMLUtils.importFromFile(file, true);
do_log_info("Checking first level");
let root = PlacesUtils.getFolderContents(PlacesUtils.unfiledBookmarksFolderId).root;
let node = root.getChild(0);
do_check_eq(node.uri, uri.spec);
root.containerOpen = false;
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
});

View File

@ -31,3 +31,4 @@ tail =
[test_818593-store-backup-metadata.js]
[test_818584-discard-duplicate-backups.js]
[test_992901-backup-unsorted-hierarchy.js]
[test_997030-bookmarks-html-encode.js]

View File

@ -34,6 +34,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "BookmarkJSONUtils",
"resource://gre/modules/BookmarkJSONUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "BookmarkHTMLUtils",
"resource://gre/modules/BookmarkHTMLUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesBackups",
"resource://gre/modules/PlacesBackups.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesTransactions",