Skip to content

Commit

Permalink
fix: hash shouldn't prevent file type detection
Browse files Browse the repository at this point in the history
Fixes #153
  • Loading branch information
ocombe committed Mar 23, 2015
1 parent ce0a9e5 commit 9e1d089
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ocLazyLoad.loaders.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions tests/unit/lazyLoad/testModule4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var testModule = angular.module('testModule4', []);
22 changes: 22 additions & 0 deletions tests/unit/specs/ocLazyLoad.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 9e1d089

Please sign in to comment.