mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-15 01:54:04 +08:00
fix(@angular-devkit/build-angular): fix base href insertion when HTML is in a single line
When HTML is in a single line using offset + 1 will cause the insertion of the base href tag in the wrong possition. Fixes #13851
This commit is contained in:
parent
901042d95b
commit
1e3c6e3ca5
@ -199,7 +199,7 @@ export class IndexHtmlWebpackPlugin {
|
||||
|
||||
treeAdapter.appendChild(baseFragment, baseElement);
|
||||
indexSource.insert(
|
||||
headElement.__location.startTag.endOffset + 1,
|
||||
headElement.__location.startTag.endOffset,
|
||||
parse5.serialize(baseFragment, { treeAdapter }),
|
||||
);
|
||||
} else {
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import { Architect } from '@angular-devkit/architect/src/index2';
|
||||
import { runTargetSpec } from '@angular-devkit/architect/testing';
|
||||
import { join, normalize, virtualFs } from '@angular-devkit/core';
|
||||
import { join, normalize, tags, virtualFs } from '@angular-devkit/core';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { BrowserBuilderOutput } from '../../src/browser/index2';
|
||||
import { browserTargetSpec, createArchitect, host } from '../utils';
|
||||
@ -41,4 +41,22 @@ describe('Browser Builder base href', () => {
|
||||
|
||||
await run.stop();
|
||||
});
|
||||
|
||||
it('should insert base href in the the correct position', async () => {
|
||||
host.writeMultipleFiles({
|
||||
'src/index.html': tags.oneLine`
|
||||
<html><head><meta charset="UTF-8"></head>
|
||||
<body><app-root></app-root></body></html>
|
||||
`,
|
||||
});
|
||||
|
||||
const overrides = { baseHref: '/myUrl' };
|
||||
const run = await architect.scheduleTarget(targetSpec, overrides);
|
||||
const output = await run.result as BrowserBuilderOutput;
|
||||
expect(output.success).toBe(true);
|
||||
const fileName = join(normalize(output.outputPath), 'index.html');
|
||||
const content = virtualFs.fileBufferToString(await host.read(normalize(fileName)).toPromise());
|
||||
expect(content).toContain('<head><base href="/myUrl"><meta charset="UTF-8"></head>');
|
||||
await run.stop();
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user