diff --git a/adapter/require.src.js b/adapter/require.src.js index 96902bbe1..85e021a0c 100644 --- a/adapter/require.src.js +++ b/adapter/require.src.js @@ -2,8 +2,30 @@ // to take advantage of testacular's heavy caching // it would work even without this hack, but with reloading all the files all the time -var load_original = window.requirejs.load; +var normalizePath = function(path) { + var normalized = []; + var parts = path.split('/'); + + for (var i = 0; i < parts.length; i++) { + if (parts[i] === '.') { + continue; + } + + if (parts[i] === '..' && normalized.length && normalized[normalized.length - 1] !== '..') { + normalized.pop(); + continue; + } + + normalized.push(parts[i]); + } + + return normalized.join('/'); +}; + +var load_original = requirejs.load; requirejs.load = function (context, moduleName, url) { + url = normalizePath(url); + if (__testacular__.files.hasOwnProperty(url)) { url = url + '?' + __testacular__.files[url]; } else { diff --git a/test/client/require.spec.js b/test/client/require.spec.js new file mode 100644 index 000000000..1ccfe04e8 --- /dev/null +++ b/test/client/require.spec.js @@ -0,0 +1,14 @@ +describe('adapter requirejs', function() { + + describe('normalizePath', function() { + + it('should normalize . and .. in the path', function() { + expect(normalizePath('/base/a/../b/./../x.js')).toBe('/base/x.js'); + }); + + + it('should preserve .. in the beginning of the path', function() { + expect(normalizePath('../../a/file.js')).toBe('../../a/file.js'); + }); + }); +}); diff --git a/test/client/testacular.conf.js b/test/client/testacular.conf.js index 4f544cb18..c0aebda86 100644 --- a/test/client/testacular.conf.js +++ b/test/client/testacular.conf.js @@ -22,7 +22,6 @@ files = [ // list of files to exclude exclude = [ - 'adapter/require.src.js' ]; // use dots reporter, as travis terminal does not support escaping sequences