Unverified Commit c21cbdf8 authored by Rahul Gaba's avatar Rahul Gaba Committed by GitHub

Fix for `next-script-for-ga` ESLint rule crashing when a method is used in…

Fix for `next-script-for-ga` ESLint rule crashing when a method is used in dangerouslySetInnerHTML (#28675)

Fixes #28635



## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
parent acf65f92
...@@ -52,8 +52,8 @@ module.exports = { ...@@ -52,8 +52,8 @@ module.exports = {
// https://developers.google.com/analytics/devguides/collection/analyticsjs#the_google_analytics_tag // https://developers.google.com/analytics/devguides/collection/analyticsjs#the_google_analytics_tag
// https://developers.google.com/tag-manager/quickstart // https://developers.google.com/tag-manager/quickstart
if ( if (
attributes.has('dangerouslySetInnerHTML') && attributes.value('dangerouslySetInnerHTML') &&
attributes.value('dangerouslySetInnerHTML')[0] attributes.value('dangerouslySetInnerHTML').length > 0
) { ) {
const htmlContent = const htmlContent =
attributes.value('dangerouslySetInnerHTML')[0].value.quasis && attributes.value('dangerouslySetInnerHTML')[0].value.quasis &&
......
...@@ -207,5 +207,35 @@ ruleTester.run('sync-scripts', rule, { ...@@ -207,5 +207,35 @@ ruleTester.run('sync-scripts', rule, {
}, },
], ],
}, },
{
code: `
export class Blah extends Head {
createGoogleAnalyticsMarkup() {
return {
__html: \`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-148481588-2');\`,
};
}
render() {
return (
<div>
<h1>Hello title</h1>
<script dangerouslySetInnerHTML={this.createGoogleAnalyticsMarkup()} />
<script async src='https://www.google-analytics.com/analytics.js'></script>
</div>
);
}
}`,
errors: [
{
message: ERROR_MSG,
type: 'JSXOpeningElement',
},
],
},
], ],
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment