Closed Bug 459196 Opened 16 years ago Closed 16 years ago

resource substitution URI doesn't work with trailing slash

Categories

(Core :: XPConnect, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: dbo, Unassigned)

Details

Calendar loads modules like "resource://calendar/modules/calUtils.jsm" and registers an alias "calendar" to the base directory (bug 459107 attachment 342400 [details] [diff] [review]). We need to cut the trailing slash to make it work:

+        let appdir = __LOCATION__.parent.parent.clone();
+
+        // Register our alias here: this code always needs to run first (triggered by app-startup)
+        let modulesDir = appdir.clone();
+        modulesDir.append("modules");
+        let modulesUri = iosvc.newFileURI(modulesDir);
+        let spec = modulesUri.spec;
+        if (spec[spec.length - 1] == '/') {
+            // we need to cut/hack around the trailing slash, otherwise our modules won't be found
+            // when loaded like "resource://calendar/modules/calUtils.jsm"; bug will be filed
+            modulesUri.spec = spec.substr(0, spec.length - 1);
+        }
+        iosvc.getProtocolHandler("resource")
+             .QueryInterface(Components.interfaces.nsIResProtocolHandler)
+             .setSubstitution("calendar", modulesUri);
Hmm. This works for me:

  setResource: function() {
    var ioService = Components.classes["@mozilla.org/network/io-service;1"]
                              .getService(Components.interfaces.nsIIOService);
    var uri = ioService.newURI("chrome://xsidebar/content/webpanels/", null, null);
    var res = ioService.getProtocolHandler("resource")
                       .QueryInterface(Components.interfaces.nsIResProtocolHandler);
    if (!res.hasSubstitution("xsidebar"))
      res.setSubstitution("xsidebar", uri);
  }

Why does the behaviour of .newFileURI differ from .newURI in this case?
Seems to be fixed in the meantime => WFM.
Status: NEW → RESOLVED
Closed: 16 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.