mirror of https://github.com/svaarala/duktape.git
Browse Source
Fix resolution of relative paths which were off by one component. For instance, if current module ID was `foo/bar` and the module require()'d `./quux`, this would be incorrectly resolved to `foo/bar/quux` instead of the expected `foo/quux`. Testcases were testing for the wrong behavior - they are also fixed by this commit. A specific bug testcase was also added for the particular issue found by andoma.v1.0-maintenance
Sami Vaarala
10 years ago
6 changed files with 119 additions and 32 deletions
@ -0,0 +1,56 @@ |
|||
/* |
|||
* Relative resolution bug in Duktape 0.12.0 |
|||
* |
|||
* https://github.com/svaarala/duktape/issues/48
|
|||
*/ |
|||
|
|||
/*--- |
|||
{ |
|||
"custom": true |
|||
} |
|||
---*/ |
|||
|
|||
/*=== |
|||
Duktape.modSearch foo |
|||
Duktape.modSearch quux |
|||
Duktape.modSearch foo/bar |
|||
Duktape.modSearch foo/quux |
|||
===*/ |
|||
|
|||
function test() { |
|||
/* |
|||
* Relative resolution from 'foo' |
|||
*/ |
|||
|
|||
Duktape.modSearch = function (id) { |
|||
print('Duktape.modSearch', id); |
|||
if (id === 'foo') { |
|||
return "var text = 'Hello world!'; // not visible outside the module\n" + |
|||
"var quux = require('./quux'); // loads quux\n" + |
|||
"exports.hello = function () { print(text); };"; |
|||
} |
|||
return ''; // return a fake empty module
|
|||
}; |
|||
void require('foo'); |
|||
|
|||
/* |
|||
* Relative resolution from 'foo/bar' |
|||
*/ |
|||
|
|||
Duktape.modSearch = function (id) { |
|||
print('Duktape.modSearch', id); |
|||
if (id === 'foo/bar') { |
|||
return "var text = 'Hello world!'; // not visible outside the module\n" + |
|||
"var quux = require('./quux'); // loads foo/quux\n" + |
|||
"exports.hello = function () { print(text); };"; |
|||
} |
|||
return ''; // return a fake empty module
|
|||
}; |
|||
void require('foo/bar'); |
|||
} |
|||
|
|||
try { |
|||
test(); |
|||
} catch (e) { |
|||
print(e.stack || e); |
|||
} |
Loading…
Reference in new issue