From ff0a90e4a899e067bb58c24e670bed4cddb11896 Mon Sep 17 00:00:00 2001 From: Kara Erickson Date: Fri, 30 Aug 2019 12:52:48 -0700 Subject: [PATCH] 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 --- packages/platform-browser/src/browser/meta.ts | 17 +++++++++++++++-- .../platform-browser/test/browser/meta_spec.ts | 12 ++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/platform-browser/src/browser/meta.ts b/packages/platform-browser/src/browser/meta.ts index aa5a421b54..29901cdb20 100644 --- a/packages/platform-browser/src/browser/meta.ts +++ b/packages/platform-browser/src/browser/meta.ts @@ -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' +}; diff --git a/packages/platform-browser/test/browser/meta_spec.ts b/packages/platform-browser/test/browser/meta_spec.ts index 9ebf174b18..317849bf46 100644 --- a/packages/platform-browser/test/browser/meta_spec.ts +++ b/packages/platform-browser/test/browser/meta_spec.ts @@ -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"';