fix(core): meta addTag() adds incorrect attribute for httpEquiv (#32531)
Meta::addTag() adds a meta tag with httpEquiv attribute instead of http-equiv when MetaDefinition contains httpEquiv property. PR Close #32531
This commit is contained in:
parent
156f9f30ae
commit
ff0a90e4a8
|
@ -180,7 +180,8 @@ export class Meta {
|
|||
}
|
||||
|
||||
private _setMetaElementAttributes(tag: MetaDefinition, el: HTMLMetaElement): HTMLMetaElement {
|
||||
Object.keys(tag).forEach((prop: string) => el.setAttribute(prop, tag[prop]));
|
||||
Object.keys(tag).forEach(
|
||||
(prop: string) => el.setAttribute(this._getMetaKeyMap(prop), tag[prop]));
|
||||
return el;
|
||||
}
|
||||
|
||||
|
@ -190,6 +191,18 @@ export class Meta {
|
|||
}
|
||||
|
||||
private _containsAttributes(tag: MetaDefinition, elem: HTMLMetaElement): boolean {
|
||||
return Object.keys(tag).every((key: string) => elem.getAttribute(key) === tag[key]);
|
||||
return Object.keys(tag).every(
|
||||
(key: string) => elem.getAttribute(this._getMetaKeyMap(key)) === tag[key]);
|
||||
}
|
||||
|
||||
private _getMetaKeyMap(prop: string): string {
|
||||
return META_KEYS_MAP[prop] || prop;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mapping for MetaDefinition properties with their correct meta attribute names
|
||||
*/
|
||||
const META_KEYS_MAP: {[prop: string]: string;} = {
|
||||
httpEquiv: 'http-equiv'
|
||||
};
|
||||
|
|
|
@ -126,6 +126,18 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
|
|||
metaService.removeTagElement(actual);
|
||||
});
|
||||
|
||||
it('should add httpEquiv meta tag as http-equiv', () => {
|
||||
metaService.addTag({httpEquiv: 'refresh', content: '3;url=http://test'});
|
||||
|
||||
const actual = metaService.getTag('http-equiv')!;
|
||||
expect(actual).not.toBeNull();
|
||||
expect(actual.getAttribute('http-equiv')).toEqual('refresh');
|
||||
expect(actual.getAttribute('content')).toEqual('3;url=http://test');
|
||||
|
||||
// clean up
|
||||
metaService.removeTagElement(actual);
|
||||
});
|
||||
|
||||
it('should add multiple new meta tags', () => {
|
||||
const nameSelector = 'name="twitter:title"';
|
||||
const propertySelector = 'property="og:title"';
|
||||
|
|
Loading…
Reference in New Issue