Bug 1594707 - In WebExtensions folder lookup, encode characters !'()* which aren't handled by encodeURIComponent. r=mkmelin a=jorgk
authorGeoff Lankow <geoff@darktrojan.net>
Mon, 11 Nov 2019 16:22:26 +1300
changeset 37273 7b4e0757efc6667b5f570909efee795615cf7848
parent 37272 8c3e92a5c1e90562fc5a3837a2a606031bd2cee8
child 37274 86baa2a8d9a13e900327125b2ed7a7041a181325
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersmkmelin, jorgk
bugs1594707
Bug 1594707 - In WebExtensions folder lookup, encode characters !'()* which aren't handled by encodeURIComponent. r=mkmelin a=jorgk
mail/components/extensions/parent/ext-mail.js
mail/components/extensions/test/xpcshell/test_ext_accounts.js
--- a/mail/components/extensions/parent/ext-mail.js
+++ b/mail/components/extensions/parent/ext-mail.js
@@ -1259,17 +1259,22 @@ function folderPathToURI(accountId, path
   // If encoded here, the folder lookup service won't find the folder.
   if (server.type == "imap") {
     return rootURI + path;
   }
   return (
     rootURI +
     path
       .split("/")
-      .map(encodeURIComponent)
+      .map(p =>
+        encodeURIComponent(p).replace(
+          /[!'()*]/g,
+          c => "%" + c.charCodeAt(0).toString(16)
+        )
+      )
       .join("/")
   );
 }
 
 const folderTypeMap = new Map([
   [Ci.nsMsgFolderFlags.Inbox, "inbox"],
   [Ci.nsMsgFolderFlags.Drafts, "drafts"],
   [Ci.nsMsgFolderFlags.SentMail, "sent"],
--- a/mail/components/extensions/test/xpcshell/test_ext_accounts.js
+++ b/mail/components/extensions/test/xpcshell/test_ext_accounts.js
@@ -124,18 +124,18 @@ add_task(async function test_accounts() 
           {
             accountId: account1Id,
             name: "Trash",
             path: "/Trash",
             type: "trash",
           },
           {
             accountId: account1Id,
-            name: "foo bar",
-            path: "/Trash/foo bar",
+            name: "foo 'bar'(!)",
+            path: "/Trash/foo 'bar'(!)",
           },
           {
             accountId: account1Id,
             name: "Ϟ",
             // This character is not supported on Windows, so it gets hashed,
             // by NS_MsgHashIfNecessary.
             path: platformInfo.os == "win" ? "/Trash/b52bc214" : "/Trash/Ϟ",
           },
@@ -160,18 +160,18 @@ add_task(async function test_accounts() 
           {
             accountId: account2Id,
             name: "Inbox",
             path: "/INBOX",
             type: "inbox",
           },
           {
             accountId: account2Id,
-            name: "foo bar",
-            path: "/INBOX/foo bar",
+            name: "foo 'bar'(!)",
+            path: "/INBOX/foo 'bar'(!)",
           },
           {
             accountId: account2Id,
             name: "Ϟ",
             path: "/INBOX/&A94-",
           },
           {
             // The trash folder magically appears at this point.
@@ -220,23 +220,25 @@ add_task(async function test_accounts() 
   iServer.username = "user";
   iServer.password = "password";
   account2.incomingServer = iServer;
 
   extension.sendMessage(account2.key);
 
   await extension.awaitMessage("create folders");
   let inbox1 = [...account1.incomingServer.rootFolder.subFolders][0];
-  inbox1.createSubfolder("foo bar", null); // Test our code can handle spaces.
+  // Test our code can handle characters that might be escaped.
+  inbox1.createSubfolder("foo 'bar'(!)", null);
   inbox1.createSubfolder("Ϟ", null); // Test our code can handle unicode.
 
   let inbox2 = [...account2.incomingServer.rootFolder.subFolders][0];
   inbox2.QueryInterface(Ci.nsIMsgImapMailFolder).hierarchyDelimiter = "/";
-  inbox2.createSubfolder("foo bar", null); // Test our code can handle spaces.
-  await PromiseTestUtils.promiseFolderAdded("foo bar");
+  // Test our code can handle characters that might be escaped.
+  inbox2.createSubfolder("foo 'bar'(!)", null);
+  await PromiseTestUtils.promiseFolderAdded("foo 'bar'(!)");
   inbox2.createSubfolder("Ϟ", null); // Test our code can handle unicode.
   await PromiseTestUtils.promiseFolderAdded("Ϟ");
 
   extension.sendMessage();
 
   await extension.awaitFinish("finished");
   await extension.unload();