diff --git a/src/amo/components/SearchResult/index.js b/src/amo/components/SearchResult/index.js index 1f5cf3bc379..94e807bb6ef 100644 --- a/src/amo/components/SearchResult/index.js +++ b/src/amo/components/SearchResult/index.js @@ -160,17 +160,11 @@ export class SearchResultBase extends React.Component { ); } - let summary = null; - if (showSummary) { - const summaryProps = {}; - if (addon) { - summaryProps.dangerouslySetInnerHTML = sanitizeHTML(addon.summary); - } else { - summaryProps.children = ; - } - - summary =

; - } + const summary = ( +

+ {addon ? addon.summary : } +

+ ); const promotedCategory = _getPromotedCategory({ addon, @@ -208,7 +202,7 @@ export class SearchResultBase extends React.Component { /> ) : null} - {summary} + {showSummary ? summary : null} {showMetadata ? (
diff --git a/src/amo/pages/Addon/index.js b/src/amo/pages/Addon/index.js index e242f6a97cb..a4ff7e06787 100644 --- a/src/amo/pages/Addon/index.js +++ b/src/amo/pages/Addon/index.js @@ -33,7 +33,7 @@ import { } from 'amo/experiments/20221130_amo_detail_category'; import { getAddonsForSlug } from 'amo/reducers/addonsByAuthors'; import { reviewListURL } from 'amo/reducers/reviews'; -import { getAddonURL, nl2br, sanitizeHTML, sanitizeUserHTML } from 'amo/utils'; +import { getAddonURL, sanitizeUserHTML } from 'amo/utils'; import { getVersionById } from 'amo/reducers/versions'; import { fetchAddon, @@ -445,24 +445,10 @@ export class AddonBase extends React.Component { const addonType = addon ? addon.type : ADDON_TYPE_EXTENSION; - const summaryProps = {}; - let showSummary = false; - if (addon) { - // Themes lack a summary so we do the inverse :-/ - // TODO: We should file an API bug about this... - const summary = addon.summary ? addon.summary : addon.description; - - if (summary && summary.length) { - summaryProps.dangerouslySetInnerHTML = sanitizeHTML(nl2br(summary), [ - 'a', - 'br', - ]); - showSummary = true; - } - } else { - summaryProps.children = ; - showSummary = true; - } + const showSummary = !addon || addon.summary?.length; + const summary = ( +

{addon ? addon.summary : }

+ ); const addonPreviews = addon ? addon.previews : []; @@ -519,9 +505,7 @@ export class AddonBase extends React.Component { {addon && }
- {showSummary ? ( -

- ) : null} + {showSummary ? summary : null}

diff --git a/src/blog-utils/StaticAddonCard/index.js b/src/blog-utils/StaticAddonCard/index.js index a7c4de6cfc4..06902a6a298 100644 --- a/src/blog-utils/StaticAddonCard/index.js +++ b/src/blog-utils/StaticAddonCard/index.js @@ -4,7 +4,6 @@ import makeClassName from 'classnames'; import { ADDON_TYPE_STATIC_THEME } from 'amo/constants'; import { getAddonIconUrl } from 'amo/imageUtils'; -import { nl2br, sanitizeHTML } from 'amo/utils'; import AddonBadges from 'amo/components/AddonBadges'; import AddonTitle from 'amo/components/AddonTitle'; import GetFirefoxButton from 'amo/components/GetFirefoxButton'; @@ -33,7 +32,6 @@ export const StaticAddonCardBase = ({ return null; } - const summary = addon.summary ? addon.summary : addon.description; const isTheme = addon.type === ADDON_TYPE_STATIC_THEME; return ( @@ -64,10 +62,7 @@ export const StaticAddonCardBase = ({
-

+

{addon.summary}

diff --git a/tests/unit/amo/pages/TestAddon.js b/tests/unit/amo/pages/TestAddon.js index e5039b5e916..af894d09064 100644 --- a/tests/unit/amo/pages/TestAddon.js +++ b/tests/unit/amo/pages/TestAddon.js @@ -661,11 +661,9 @@ describe(__filename, () => { ).toBeTruthy(); }); - it('sanitizes a summary', () => { - const summaryText = 'some summary text'; - addon.summary = createLocalizedString( - `${summaryText}`, - ); + it('renders html as plaintext', () => { + const summaryText = ''; + addon.summary = createLocalizedString(summaryText); renderWithAddon(); // Verify that the summary text exists without the script tag. @@ -677,30 +675,6 @@ describe(__filename, () => { ).not.toBeInTheDocument(); }); - it('adds
tags for newlines in a summary', () => { - addon.summary = createLocalizedString('Hello\nI am an\n add-on.'); - renderWithAddon(); - - const addonSummary = screen.getByClassName('Addon-summary'); - expect(within(addonSummary).queryAllByTagName('br')).toHaveLength(2); - }); - - it('sanitizes bad description HTML', () => { - const descriptionText = 'some description text'; - addon.summary = createLocalizedString( - `${descriptionText}`, - ); - renderWithAddon(); - - // Verify that the summary text exists without the script tag. - expect(screen.getByText(descriptionText)).toBeInTheDocument(); - // Verify that no script tags exist in the summary. - const addonDescription = screen.getByClassName('AddonDescription'); - expect( - within(addonDescription).queryByTagName('script'), - ).not.toBeInTheDocument(); - }); - // This is a test helper that can be used to test the integration between // a ShowMoreCard and contentId. const testContentId = async ({ @@ -935,18 +909,16 @@ describe(__filename, () => { expect(screen.getByText(summary)).toBeInTheDocument(); }); - it('renders a summary with links', () => { - const summaryText = 'some summary text'; - const linkText = 'link destination'; - addon.summary = createLocalizedString( - `${summaryText} ${linkText}`, - ); + it('does not render links in a summary', () => { + const linkText = 'click me!'; + const summaryText = `blah blah ${linkText}`; + addon.summary = createLocalizedString(summaryText); renderWithAddon(); + expect(screen.getByTextAcrossTags(summaryText)).toBeInTheDocument(); expect( - screen.getByTextAcrossTags(`${summaryText} ${linkText}`), - ).toBeInTheDocument(); - expect(screen.getByRole('link', { name: linkText })).toBeInTheDocument(); + screen.queryByRole('link', { name: linkText }), + ).not.toBeInTheDocument(); }); it('renders an amo icon image', () => { diff --git a/tests/unit/blog-utils/TestStaticAddonCard.js b/tests/unit/blog-utils/TestStaticAddonCard.js index 59870c52b28..65804edfbcb 100644 --- a/tests/unit/blog-utils/TestStaticAddonCard.js +++ b/tests/unit/blog-utils/TestStaticAddonCard.js @@ -86,19 +86,9 @@ describe(__filename, () => { ).toBeInTheDocument(); }); - it('displays the description if there is no summary', () => { - const addon = createInternalAddonWithLang({ ...fakeAddon, summary: null }); - - render({ addon }); - - expect(screen.getByText(addon.description)).toBeInTheDocument(); - }); - - it('sanitizes the summary', () => { - const plainText = 'Some safe text'; - const scriptHTML = createLocalizedString( - `${plainText}`, - ); + it('renders html as plaintext', () => { + const plainText = ''; + const scriptHTML = createLocalizedString(plainText); render({ addon: createInternalAddonWithLang({ @@ -107,13 +97,9 @@ describe(__filename, () => { }), }); + expect(screen.getByText(plainText)).toBeInTheDocument(); // Make sure an actual script tag was not created. expect(screen.queryByTagName('script')).not.toBeInTheDocument(); - // Make sure the script has been removed. - expect(screen.getByText(plainText)).toBeInTheDocument(); - expect( - screen.getByClassName('StaticAddonCard-summary'), - ).not.toHaveTextContent('