diff --git a/common/static/common/js/utils/clamp-html.js b/common/static/common/js/utils/clamp-html.js index c9e33660b4..9486e1ac6e 100644 --- a/common/static/common/js/utils/clamp-html.js +++ b/common/static/common/js/utils/clamp-html.js @@ -12,6 +12,10 @@ function clampHtmlByWords(root, wordsLeft) { 'use strict'; + if (root.nodeName === 'SCRIPT' || root.nodeName === 'LINK') { + return wordsLeft; // early exit and ignore + } + var remaining = wordsLeft; var nodes = Array.from(root.childNodes ? root.childNodes : []); var words, chopped; diff --git a/common/static/common/js/utils/clamp-html.test.jsx b/common/static/common/js/utils/clamp-html.test.jsx index 381a8461ca..02b8b5ab94 100644 --- a/common/static/common/js/utils/clamp-html.test.jsx +++ b/common/static/common/js/utils/clamp-html.test.jsx @@ -3,6 +3,8 @@ import ReactDOM from 'react-dom'; import { clampHtmlByWords } from './clamp-html'; let container; +const scriptTag = ''; +const stylesheet = ''; beforeEach(() => { container = document.createElement("div"); @@ -25,6 +27,9 @@ describe('ClampHtml', () => { ['a aa aaa', 2, 'a aa…'], ['a aa aaa ab', 3, 'a aa aaa…'], ['a aa ab b c', 4, 'a aa ab b…'], + [scriptTag + 'a b c', 2, scriptTag + 'a b…'], + [stylesheet + 'a b c', 2, stylesheet + 'a b…'], + [scriptTag + stylesheet + 'a b c', 2, scriptTag + stylesheet + 'a b…'], ])('clamps by words: %s, %i', (input, wordsLeft, expected) => { const div = ReactDOM.render(
, container); clampHtmlByWords(div, wordsLeft);