Opened 8 years ago

Closed 8 years ago

#13651 closed defect (wontfix)

Error loading optimized local resouces with cdn dojo, if "//" is used in the code.

Reported by: Marko Reiprecht Owned by: Rawld Gill
Priority: high Milestone: 1.7
Component: BuildSystem Version: 1.6.1
Keywords: Cc:
Blocked By: Blocking:

Description

REPRODUCTION

  • create html with dojo from a cdn
  • configure some locale modules like
         dojoConfig.baseUrl = "./";
         dojoConfig.modulePaths = {
                    ct: "js/ct"
         };
    
  • try to load a local resource with dojo.require like:

dojo.require("ct.test")

The may have following content for reproduction:

if(!dojo._hasResource["ct.testIncludedFile"]){dojo._hasResource["ct.testIncludedFile"]=true;dojo.provide("ct.testIncludedFile");ct.url = "//";}if(!dojo._hasResource["ct.request"]){dojo._hasResource["ct.request"]=true;dojo.provide("ct.test");ct.url2 = "//";}

Please note that the code above is in one line (after optimized build, what leads to the problem).

EXPECTED

Resource normally loaded

ACTUAL

Resouce is not correctly loaded after some time following exception is created:

uncaught exception: Could not load cross-domain resources: ct.test

EVALUATION

The problem is the pattern:

var depContents = contents.replace(/(\/\*([\s\S]*?)\*\/|\/\/(.*)$)/mg , "");

in method dojo._xdCreateResource in xdloader.js

It the second part of the regex finds all double slashes also in strings. And removes all following characters from the file content, bevor searching for "dojo.provide" statements.

So the dojo.provide for "ct.test" is not found and the loading fails.

WORKARROUND

  • create own xd build of the local files and use the <script> tag loading
  • use local dojo copy
  • use unicode encoding for '/' = '\u002F' in your own files, so that the regex does not match

POSSIBLE SOLUTION

Change the second part of the regex so:

contents.replace(/(\/\*([\s\S]*?)\*\/|^\s*\/\/(.*)$)/mg , "");

'\s*' is added, which checks that before '' is only white space.

Change History (4)

comment:1 Changed 8 years ago by bill

Component: GeneralBuildSystem
Owner: set to Rawld Gill

comment:2 Changed 8 years ago by Rawld Gill

Status: newassigned

comment:3 Changed 8 years ago by Rawld Gill

Milestone: tbd1.7

comment:4 Changed 8 years ago by Rawld Gill

Resolution: wontfix
Status: assignedclosed

Yes, you are quite correct that those regexs will cause problems for some code. If you express your modules in AMD, the loader can be put in the async mode which injects modules via script elements, which works xdomain. Otherwise using an encoding as indicated by your workaround bullet point 3 is the only solution as of v1.7 since the v1.7 builder still uses regexs. We are planning on moving to a proper parser for the build system in 1.8 which will eliminate this problem.

Also, owing to Javascripts literal regex syntax, it is impossible to construct a regex that eliminates comments...you must parse the code. Even then, the language has an ambiguity...see the 2nd and 3rd paragraphs in Chapter 7 of ECMA-262 (http://ecma262-5.com/ELS5_HTML.htm#Section_7)

Note: See TracTickets for help on using tickets.