Page 1 of 1

[Bug] Copying URI to clipboard breaks DOMParser constructor

PostPosted: Mon Apr 04, 2016 12:10 am
by Odyseus
Signed fixed version can be found on this topic.

Hello, g@ys.

Like the title says, whenever I copy to the clipboard a CB button URI, the global constructor new DOMParser() stops working completely. The only way to recover the DOMParser functionality is to restart the application. This happens with all versions of Firefox (from Stable to Nightly) with Custom Buttons version 0.0.5.8.9. In Palemoon and SeaMonkey this problem doesn't exists.

Steps to reproduce the problem
  • Open Browser console and execute this code:
    Code: Select all
    (new DOMParser).parseFromString("<tag></tag>", "application/xml").documentElement;
  • Right click on any Custom Button and copy its URL to the clipboard.
  • Execute again the code from step one and the DOMParser fails with this error:
    [Exception... "Unexpected error" nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)" location: "JS frame :: debugger eval code :: <TOP_LEVEL> :: line 1" data: no]

Notes
  • Not just the new DOMParser() constructor breaks. The nsIDOMParser service is also rendered useless.
  • I reverted back to Custom Buttons versions 0.0.5.8.8 and 0.0.5.8.7. The exact same problem.
  • I reverted back to Custom Buttons version 0.0.5.8.6. The DOMParser constructor works perfectly always.

Re: [Bug] Copying URI to clipboard breaks DOMParser construc

PostPosted: Tue Apr 05, 2016 12:44 am
by Odyseus
While doing some more tests, I tracked down the problem to the xmlFormatURI method, inside the cbbutton.js file. I found out some things:
  • Using the nsIDOMParser service in any way (parseFromString or parseFromStream) inside the xmlFormatURI method breaks the new DOMParser() constructor globally.
  • Using the new DOMParser() constructor inside the xmlFormatURI method doesn't break its usage globally.
  • Using the XMLHttpRequest method, as used in the past, inside the xmlFormatURI method doesn't break the new DOMParser() constructor usage.
In the code bellow I modified the xmlFormatURI method and it works "without any problems".
Code: Select all
xmlFormatURI: function(oBtn) {
   var cbs = Components.classes["@xsms.nm.ru/custombuttons/cbservice;1"].getService(Components.interfaces.cbICustomButtonsService);
   var xmlchan = cbs.getChannel("chrome://custombuttons/content/nbftemplate.xml");
   var instr = xmlchan.open();
   /**
    * nsIDOMParser used here breaks the new DOMParser contructor globally on all Firefox versions.
    */
   // var dp = Components.classes["@mozilla.org/xmlextras/domparser;1"].createInstance(Components.interfaces.nsIDOMParser);
   // var doc = dp.parseFromStream(instr, null, instr.available(), "application/xml");
   var bis = Components.classes['@mozilla.org/binaryinputstream;1'].createInstance(Components.interfaces.nsIBinaryInputStream);
   bis.setInputStream(instr);
   var templateStr = bis.readBytes(bis.available());
   var doc = (new DOMParser()).parseFromString(templateStr, "application/xml");
   oBtn.setText(doc, "name", oBtn.name, false);
   oBtn.setText(doc, "mode", oBtn.cbMode, false);
   oBtn.setText(doc, "image", oBtn.image || oBtn.cbStdIcon, true);
   oBtn.setText(doc, "code", oBtn.cbCommand, true);
   oBtn.setText(doc, "initcode", oBtn.cbInitCode, true);
   oBtn.setText(doc, "accelkey", oBtn.cbAccelKey, true);
   oBtn.setText(doc, "help", oBtn.Help, true);
   if (oBtn.parameters.attributes) {
      var atts = oBtn.parameters.attributes;
      for (var i in atts)
         this.setAttribute(doc, i, atts[i]);
   }
   var ser = new XMLSerializer();
   var data = ser.serializeToString(doc);
   return "custombutton://" + escape(data);
},

Re: [Bug] Copying URI to clipboard breaks DOMParser construc

PostPosted: Sat Apr 23, 2016 11:02 pm
by makondo
I wonder why my addons manager says it's 5.8.8 while the file says it's 5.8.9

2.png
2.png (41.56 KiB) Viewed 679 times

Re: [Bug] Copying URI to clipboard breaks DOMParser construc

PostPosted: Sun Apr 24, 2016 3:02 am
by Odyseus
It's because it was the 0.0.5.8.8 version. This time, instead of downloading the last version of the add-on and edit its files, I built the extension from the GitHub sources. It seems that in there the files are not updated that often.

I deleted the file from my previous post and uploaded the latest version with that little fix/workaround in it.

Re: [Bug] Copying URI to clipboard breaks DOMParser construc

PostPosted: Sun Apr 24, 2016 3:34 am
by makondo
Thanks

Re: [Bug] Copying URI to clipboard breaks DOMParser construc

PostPosted: Mon Oct 24, 2016 2:51 pm
by trespassersW
Odyseus wrote: • Not just the new DOMParser() constructor breaks. The nsIDOMParser service is also rendered useless.

Rather, it makes sense to file this bug in Bugzilla :?: