angular / angular/angular

Double slash `templateUrls` should not be allowed

Open
#48,768 0 comments 0 reactions 0 assignees View on GitHub
area: compiler
Dominant language
TypeScript
Stars
101k
Forks
27.5k
Avg merge
1d 19h
Merged PRs (30d)
288

Description

### Which @angular/* package(s) are the source of the bug?

compiler-cli

### Is this a regression?

Yes

### Description

It is apparently possible to write a component using a leading `//` in a `templateUrl` like so:

```typescript
// path/to/my/component/my-component.ts

@Component({
selector: 'my-component',
templateUrl: '//path/to/my/component/my-component.html',
})
class MyComponent {}
```

```html

Hello, World!

```

This shouldn't be allowed as it's not a valid path. In particular this looks like a Bazel path, which makes it seem intentional when it really isn't.

@devversion [investigated this](https://github.com/angular/components/pull/19320#discussion_r435515440) a little while ago, and it does seem to be unintentionally supported. There are a handful of usages in google3, but mostly in experimental directories. It likely would not be a difficult migration. We should also clean up [this code path](http://go/build-cleaner-ngc-leading-slashes) in Build Cleaner.

### Please provide a link to a minimal reproduction of the bug

_No response_

### Please provide the exception or error you saw

_No response_

### Please provide the environment you discovered this bug in (run `ng version`)

_No response_

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by tracing how compiler-cli resolves component templateUrl values, then inspect the linked Build Cleaner code path for leading slashes. Add regression coverage for the shown leading-double-slash case and verify that such a templateUrl is rejected while valid paths continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.