Skip to content

Commit

Permalink
fix(core): meta addTag() adds incorrect attribute for httpEquiv (#32531)
Browse files Browse the repository at this point in the history
Meta::addTag() adds a meta tag with httpEquiv attribute instead of http-equiv when
MetaDefinition contains httpEquiv property.

PR Close #32531
  • Loading branch information
kara authored and AndrewKushnir committed Nov 20, 2020
1 parent 156f9f3 commit ff0a90e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/platform-browser/src/browser/meta.ts
Expand Up @@ -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;
}

Expand All @@ -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'
};
12 changes: 12 additions & 0 deletions packages/platform-browser/test/browser/meta_spec.ts
Expand Up @@ -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"';
Expand Down

0 comments on commit ff0a90e

Please sign in to comment.