Skip to content

Commit 215c4aa

Browse files
fix(compiler): detect and report error for views with empty templateUrl
Fixes angular#3762 Closes angular#3768
1 parent 3871f89 commit 215c4aa

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

modules/angular2/src/core/compiler/compiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ export class Compiler {
301301
this._urlResolver.resolve(this._appUrl, this._componentUrlMapper.getUrl(component));
302302
var templateAbsUrl = null;
303303
var styleAbsUrls = null;
304-
if (isPresent(view.templateUrl)) {
304+
if (isPresent(view.templateUrl) && view.templateUrl.trim().length > 0) {
305305
templateAbsUrl = this._urlResolver.resolve(componentUrl, view.templateUrl);
306306
} else if (isPresent(view.template)) {
307307
// Note: If we have an inline template, we also need to send

modules/angular2/test/core/compiler/compiler_spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,26 @@ export function main() {
149149
});
150150
}));
151151

152+
it('should not fill templateAbsUrl given template url with empty string',
153+
inject([AsyncTestCompleter], (async) => {
154+
cmpUrlMapper.setComponentUrl(MainComponent, '/cmp/main.js');
155+
captureTemplate(new ViewMetadata({template: null, templateUrl: ''}))
156+
.then((renderTpl) => {
157+
expect(renderTpl.templateAbsUrl).toBe(null);
158+
async.done();
159+
});
160+
}));
161+
162+
it('should not fill templateAbsUrl given template url with blank string',
163+
inject([AsyncTestCompleter], (async) => {
164+
cmpUrlMapper.setComponentUrl(MainComponent, '/cmp/main.js');
165+
captureTemplate(new ViewMetadata({template: null, templateUrl: ' '}))
166+
.then((renderTpl) => {
167+
expect(renderTpl.templateAbsUrl).toBe(null);
168+
async.done();
169+
});
170+
}));
171+
152172
it('should fill templateAbsUrl given url template', inject([AsyncTestCompleter], (async) => {
153173
cmpUrlMapper.setComponentUrl(MainComponent, '/cmp/main.js');
154174
captureTemplate(new ViewMetadata({templateUrl: 'tpl/main.html'}))

0 commit comments

Comments
 (0)