From 9e1d089413e09b14b7b46d5ff5de4612613be5e9 Mon Sep 17 00:00:00 2001 From: Olivier Combe Date: Mon, 23 Mar 2015 22:19:29 +0100 Subject: [PATCH] fix: hash shouldn't prevent file type detection Fixes #153 --- src/ocLazyLoad.loaders.core.js | 2 +- tests/unit/lazyLoad/testModule4.js | 1 + tests/unit/specs/ocLazyLoad.spec.js | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/unit/lazyLoad/testModule4.js diff --git a/src/ocLazyLoad.loaders.core.js b/src/ocLazyLoad.loaders.core.js index 492026d..a5ca5f2 100644 --- a/src/ocLazyLoad.loaders.core.js +++ b/src/ocLazyLoad.loaders.core.js @@ -37,7 +37,7 @@ } if(!file_type) { - if((m = /[.](css|less|html|htm|js)?(\?.*)?$/.exec(path)) !== null) { // Detect file type via file extension + if((m = /[.](css|less|html|htm|js)?((\?|#).*)?$/.exec(path)) !== null) { // Detect file type via file extension file_type = m[1]; } else if(!$delegate.jsLoader.hasOwnProperty('ocLazyLoadLoader') && $delegate.jsLoader.hasOwnProperty('load')) { // requirejs file_type = 'js'; diff --git a/tests/unit/lazyLoad/testModule4.js b/tests/unit/lazyLoad/testModule4.js new file mode 100644 index 0000000..02d7b3f --- /dev/null +++ b/tests/unit/lazyLoad/testModule4.js @@ -0,0 +1 @@ +var testModule = angular.module('testModule4', []); diff --git a/tests/unit/specs/ocLazyLoad.spec.js b/tests/unit/specs/ocLazyLoad.spec.js index b1fe122..5757573 100644 --- a/tests/unit/specs/ocLazyLoad.spec.js +++ b/tests/unit/specs/ocLazyLoad.spec.js @@ -254,6 +254,28 @@ describe('Module: oc.lazyLoad', function() { }); }); + it('should be able to lazy load a module when the url ends with a hash', function(done) { + var interval = triggerDigests(); + + $ocLazyLoad.load(lazyLoadUrl + 'testModule4.js#hash').then(function success(res) { + window.clearInterval(interval); + + // Test the module loading + expect(angular.module('testModule4')).toBeDefined(); + + // Test the module loading + expect(res).toBeDefined(); + + // because debug is set to false, we shouldn't have any log + $log.assertEmpty(); + + done(); + }, function error(err) { + window.clearInterval(interval); + throw err; + }); + }); + it('should reject the promise when the jsLoader is unable to load a file', function(done) { var interval = triggerDigests();