[Bug] Copying URI to clipboard breaks DOMParser constructor

Post information about bugs here

[Bug] Copying URI to clipboard breaks DOMParser constructor

Postby Odyseus » Mon Apr 04, 2016 12:10 am

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.
Last edited by Odyseus on Fri Mar 10, 2017 9:15 pm, edited 3 times in total.
Odyseus
 
Posts: 434
Joined: Sun Mar 10, 2013 12:51 pm

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

Postby Odyseus » Tue Apr 05, 2016 12:44 am

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);
},
Last edited by Odyseus on Fri Mar 10, 2017 9:15 pm, edited 13 times in total.
Odyseus
 
Posts: 434
Joined: Sun Mar 10, 2013 12:51 pm

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

Postby makondo » Sat Apr 23, 2016 11:02 pm

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 773 times
makondo
 
Posts: 1636
Joined: Sun Dec 25, 2011 7:17 pm

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

Postby Odyseus » Sun Apr 24, 2016 3:02 am

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.
Odyseus
 
Posts: 434
Joined: Sun Mar 10, 2013 12:51 pm

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

Postby makondo » Sun Apr 24, 2016 3:34 am

Thanks
Last edited by makondo on Mon Oct 24, 2016 4:22 pm, edited 1 time in total.
makondo
 
Posts: 1636
Joined: Sun Dec 25, 2011 7:17 pm

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

Postby trespassersW » Mon Oct 24, 2016 2:51 pm

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 :?:
trespassersW
 
Posts: 12
Joined: Fri Aug 12, 2016 4:42 pm


Return to Bug report

cron