Ghost/ghost/admin/tests/unit/helpers/highlighted-text-test.js
Jono M 62f7600aa4
Update search text highlighting to escape HTML (#16760)
refs: https://github.com/TryGhost/Team/issues/2390

Escapes each matched and non-matched segment of the post title in the
admin search field, to make sure they're displayed in plain text but
still have matches highlighted.
2023-05-11 09:53:05 +12:00

23 lines
724 B
JavaScript

import {
describe,
it
} from 'mocha';
import {expect} from 'chai';
import {
highlightedText
} from 'ghost-admin/helpers/highlighted-text';
describe('Unit: Helper: highlighted-text', function () {
it('works', function () {
let result = highlightedText(['Test', 'e']);
expect(result).to.be.an('object');
expect(result.string).to.equal('T<span class="highlight">e</span>st');
});
it('escapes html', function () {
let result = highlightedText(['<script>alert("oops")</script>', 'oops']);
expect(result).to.be.an('object');
expect(result.string).to.equal('&lt;script&gt;alert(&quot;<span class="highlight">oops</span>&quot;)&lt;/script&gt;');
});
});