Skip to content

dots (.) in keys for the config.paths breaks lookup for later non-dotted final file #123

@metatoaster

Description

@metatoaster

Firstly I had this test done in requirejs 2.3.2, requirejs-text 2.0.12, (later I have a test for the latest version (requirejs-text 2.0.15))

var requirejsOptions = ({"paths": { 
  'nodot/target': '/srv/tmp/nodot/target',
  'dot.d/target': '/srv/tmp/dot.d/target',
  'nodot/extra.target': '/srv/tmp/nodot/extra.target',
  'dot.d/extra.target': '/srv/tmp/dot.d/extra.target',
}})
requirejs.config(requirejsOptions);

The above configuration is set up to effectively append /srv/tmp/ to the affected paths to illustrate the issue at hand; the test matrix I used:

require([
  'text!nodot/target',             // pass /srv/tmp/nodot/target
  'text!nodot/target.ext',         // pass /srv/tmp/nodot/target.ext
  'text!nodot/target/file',        // pass /srv/tmp/nodot/target/file
                                   // ____ note missing trailing dot below
  'text!nodot/target/file.',       // FAIL /srv/tmp/nodot/target/file
  'text!dot.d/target',             // FAIL ./dot.d/target
  'text!dot.d/target.ext',         // pass /srv/tmp/dot.d/target.ext
  'text!dot.d/target/file',        // FAIL ./dot.d/target/file
  'text!dot.d/target/file.',       // pass /srv/tmp/dot.d/target/file.
  'text!nodot/extra.target',       // FAIL ./nodot/extra.target
  'text!nodot/extra.target.ext',   // pass /srv/tmp/nodot/extra.target.ext
  'text!nodot/extra.target/file',  // FAIL ./nodot/extra.target/file
  'text!nodot/extra.target/file.', // pass /srv/tmp/nodot/extra.target/file.
  'text!dot.d/extra.target',       // FAIL ./dot.d/extra.target
  'text!dot.d/extra.target.ext',   // pass /srv/tmp/dot.d/extra.target.ext
  'text!dot.d/extra.target/file',  // FAIL ./dot.d/extra.target/file
  'text!dot.d/extra.target/file.', // pass /srv/tmp/dot.d/extra.target/file.
], function() {
});

The above is somewhat closer to expected behaviour, where the passing tests have accessed urls with /srv/tmp/ prepended as configured.

With 2.0.15, same configuration:

require([
                                   // ____ note all missing trailing dot below
  'text!nodot/target',             // pass /srv/tmp/nodot/target
  'text!nodot/target.ext',         // pass /srv/tmp/nodot/target.ext
  'text!nodot/target/file',        // pass /srv/tmp/nodot/target/file
  'text!nodot/target/file.',       // FAIL /srv/tmp/nodot/target/file
  'text!dot.d/target',             // FAIL ./dot.d/target
  'text!dot.d/target.ext',         // pass /srv/tmp/dot.d/target.ext
  'text!dot.d/target/file',        // FAIL ./dot.d/target/file
  'text!dot.d/target/file.',       // FAIL ./dot.d/target/file
  'text!nodot/extra.target',       // FAIL ./nodot/extra.target
  'text!nodot/extra.target.ext',   // pass /srv/tmp/nodot/extra.target.ext
  'text!nodot/extra.target/file',  // FAIL ./nodot/extra.target/file
  'text!nodot/extra.target/file.', // FAIL ./nodot/extra.target/file
  'text!dot.d/extra.target',       // FAIL ./dot.d/extra.target
  'text!dot.d/extra.target.ext',   // pass /srv/tmp/dot.d/extra.target.ext
  'text!dot.d/extra.target/file',  // FAIL ./dot.d/extra.target/file
  'text!dot.d/extra.target/file.', // FAIL ./dot.d/extra.target/file
], function() {
});

If I could get an explanation on how or why a . character in a directory could just later stop a proper file lookup that do not have a filename extension it would be great. Also trailing dots, now that the latest version managed to consume and ignore that completely.

Further to the above, there are a couple more behaviours that I am unsure of (using same configuration as above), they are marked with ????

require([
  'text!nodot/target.d/file', // ???? /srv/tmp/nodot/target.d/file
  'text!nodot/targetd/file',  // ???? ./nodot/targetd/file
], function() {
});

The first one is especially puzzling since it basically treat .d/file as a filename extension to nodot/target, even though file is really a file living under the nodot/target.d directory, which is tracked ambiguously through the configuration.

Finally, for completion sake, doing this directly without the plugin (and account for the automatic .js filename extension appending), this is what I saw.

require([
  'nodot/target',             // pass /srv/tmp/nodot/target.js
  'nodot/target.ext',         // ???? ./nunja/nodot/target/ext.js
  'nodot/target/file',        // pass /srv/tmp/nodot/target/file.js
  'nodot/target/file.',       // pass /srv/tmp/nodot/target/file..js
  'dot.d/target',             // pass /srv/tmp/dot.d/target.js
  'dot.d/target.ext',         // ???? ./dot.d/target.ext.js
  'dot.d/target/file',        // pass /srv/tmp/dot.d/target/file.js
  'dot.d/target/file.',       // pass /srv/tmp/dot.d/target/file..js
  'nodot/extra.target',       // pass /srv/tmp/nodot/extra.target.js
  'nodot/extra.target.ext',   // ???? ./nodot/extra.target.ext.js
  'nodot/extra.target/file',  // pass /srv/tmp/nodot/extra.target/file.js
  'nodot/extra.target/file.', // pass /srv/tmp/nodot/extra.target/file..js
  'dot.d/extra.target',       // pass /srv/tmp/dot.d/extra.target.js 
  'dot.d/extra.target.ext',   // ???? ./dot.d/extra.target.ext
  'dot.d/extra.target/file',  // pass /srv/tmp/dot.d/extra.target/file.js 
  'dot.d/extra.target/file.', // pass /srv/tmp/dot.d/extra.target/file..js 
], function() {
});

require([
  'nodot/target.d/file', // ???? ./nodot/target.d/file.js
  'nodot/targetd/file',  // ???? ./nodot/targetd/file.js
], function() {
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions