From e43bb77c334c2193c0c0b416694fb5d78616c4b8 Mon Sep 17 00:00:00 2001 From: Aaron Dewey Date: Thu, 9 May 2019 14:12:19 -0700 Subject: [PATCH] add helmetKey attributeKey, tests --- src/HelmetConstants.js | 1 + src/HelmetUtils.js | 5 ++++ test/HelmetDeclarativeTest.js | 45 +++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/src/HelmetConstants.js b/src/HelmetConstants.js index 1543cbfc..713aff06 100644 --- a/src/HelmetConstants.js +++ b/src/HelmetConstants.js @@ -28,6 +28,7 @@ export const TAG_PROPERTIES = { HTTPEQUIV: "http-equiv", INNER_HTML: "innerHTML", ITEM_PROP: "itemprop", + KEY: "helmetKey", NAME: "name", PROPERTY: "property", REL: "rel", diff --git a/src/HelmetUtils.js b/src/HelmetUtils.js index c46f8385..c9ab4076 100644 --- a/src/HelmetUtils.js +++ b/src/HelmetUtils.js @@ -150,6 +150,11 @@ const getTagsFromPropsList = (tagName, primaryAttributes, propsList) => { ) { primaryAttributeKey = attributeKey; } + + if (attributeKey === TAG_PROPERTIES.KEY) { + primaryAttributeKey = attributeKey; + break; + } } if (!primaryAttributeKey || !tag[primaryAttributeKey]) { diff --git a/test/HelmetDeclarativeTest.js b/test/HelmetDeclarativeTest.js index bdcf5229..67b5508b 100644 --- a/test/HelmetDeclarativeTest.js +++ b/test/HelmetDeclarativeTest.js @@ -2301,6 +2301,51 @@ describe("Helmet - Declarative API", () => { done(); }); }); + + it("overrides duplicate helmetKey scripts", done => { + const scriptInnerHTML = ` + { + "@context": "http://schema.org", + "@type": "NewsArticle", + "url": "http://localhost/helmet" + } + `; + ReactDOM.render( +
+ +