diff --git a/src/core/utilities.js b/src/core/utilities.js index a1bbe16b6..6b8d51dcd 100644 --- a/src/core/utilities.js +++ b/src/core/utilities.js @@ -167,3 +167,25 @@ export function errorString (error) { return resultErrorString; } } + +export function escapeText (str) { + if (!str) { + return ''; + } + + // Both single quotes and double quotes (for attributes) + return ('' + str).replace(/['"<>&]/g, function (s) { + switch (s) { + case "'": + return '''; + case '"': + return '"'; + case '<': + return '<'; + case '>': + return '>'; + case '&': + return '&'; + } + }); +} diff --git a/src/html-reporter/diff.js b/src/html-reporter/diff.js index bbe306d9f..eb8fb97c5 100644 --- a/src/html-reporter/diff.js +++ b/src/html-reporter/diff.js @@ -1,5 +1,5 @@ import QUnit from '../core'; -import { escapeText } from './html'; +import { escapeText } from '../core/utilities'; /* * This file is a modified version of google-diff-match-patch's JavaScript implementation diff --git a/src/html-reporter/html.js b/src/html-reporter/html.js index bad16362f..7a4ba76b6 100644 --- a/src/html-reporter/html.js +++ b/src/html-reporter/html.js @@ -1,7 +1,6 @@ import QUnit from '../core'; -import { extend, errorString } from '../core/utilities'; +import { extend, errorString, escapeText } from '../core/utilities'; import { window, document, navigator, console, StringMap } from '../globals'; -import './urlparams'; import fuzzysort from 'fuzzysort'; const stats = { @@ -10,29 +9,6 @@ const stats = { completed: 0 }; -// Escape text for attribute or text content. -export function escapeText (str) { - if (!str) { - return ''; - } - - // Both single quotes and double quotes (for attributes) - return ('' + str).replace(/['"<>&]/g, function (s) { - switch (s) { - case "'": - return '''; - case '"': - return '"'; - case '<': - return '<'; - case '>': - return '>'; - case '&': - return '&'; - } - }); -} - (function () { // Don't load the HTML Reporter on non-browser environments if (!window || !document) { diff --git a/src/html-reporter/reporter.js b/src/html-reporter/reporter.js index ebdd17b57..7b41864b9 100644 --- a/src/html-reporter/reporter.js +++ b/src/html-reporter/reporter.js @@ -1,3 +1,4 @@ import './fixture'; import './diff'; +import './urlparams'; import './html';