Skip to content

Commit 61701ab

Browse files
Ayudhclydin
authored andcommitted
fix(@angular-devkit/build-angular): handle base tag endOffset in index.html generation
* fix endOffset if the base tag is already present * add test case for this Closes #18381
1 parent 7b8e217 commit 61701ab

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/utilities/index-file/augment-index-html.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export async function augmentIndexHtml(params: AugmentIndexHtmlOptions): Promise
179179
treeAdapter.setTemplateContent(baseFragment, baseElement);
180180
indexSource.replace(
181181
baseElement.sourceCodeLocation.startOffset,
182-
baseElement.sourceCodeLocation.endOffset,
182+
baseElement.sourceCodeLocation.endOffset - 1,
183183
parse5.serialize(baseFragment, { treeAdapter }),
184184
);
185185
}

packages/angular_devkit/build_angular/src/angular-cli-files/utilities/index-file/augment-index-html_spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ describe('augment-index-html', () => {
4949
`);
5050
});
5151

52+
it('should replace base href value', async () => {
53+
const source = augmentIndexHtml({
54+
...indexGeneratorOptions,
55+
inputContent: '<html><head><base href="/"></head><body></body></html>',
56+
baseHref: '/Apps/',
57+
});
58+
59+
const html = await source;
60+
expect(html).toEqual(oneLineHtml`
61+
<html>
62+
<head><base href="/Apps/">
63+
</head>
64+
<body>
65+
</body>
66+
</html>
67+
`);
68+
});
69+
5270
it(`should emit correct script tags when having 'module' and 'non-module' js`, async () => {
5371
const es2015JsFiles: FileInfo[] = [
5472
{ file: 'runtime-es2015.js', extension: '.js', name: 'main' },

packages/angular_devkit/build_angular/src/browser/specs/service-worker_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ describe('Browser Builder service worker', () => {
235235
hashTable: {
236236
'/foo/bar/favicon.ico': '84161b857f5c547e3699ddfbffc6d8d737542e01',
237237
'/foo/bar/assets/folder-asset.txt': '617f202968a6a81050aa617c2e28e1dca11ce8d4',
238-
'/foo/bar/index.html': 'a5359e8e1a516683b32bbb2f9e8bf402dae4738e',
238+
'/foo/bar/index.html': 'e92a780dba6f6099adafb72d7611f6660a91a70b',
239239
},
240240
}));
241241

0 commit comments

Comments
 (0)