/* eslint-env mocha */
import { expect } from 'chai';
import { Markdown } from 'meteor/wekan-markdown';
// Tests for the Admin Panel / Features / Security "Always show all code as plain
// text" toggle. When enabled, the markdown helper renders the raw source escaped
// (via escapeHtmlSource) so hidden content — HTML comments, the target of markdown
// links, JavaScript and any other code — is shown literally, not executed. Here we
// pin escapeHtmlSource, the escaper that makes that safe.
describe('markdown — always show code as plain text (escapeHtmlSource)', function() {
const esc = Markdown.escapeHtmlSource;
it('escapes ")).to.equal(
"<script>alert('x')</script>",
);
});
it('reveals HTML comments instead of hiding them', function() {
expect(esc('')).to.equal('<!-- secret -->');
});
it('escapes ampersand first so entities are not double-decoded', function() {
expect(esc('a & b')).to.equal('a & b');
expect(esc('<')).to.equal('<');
});
it('escapes quotes used in markup attributes', function() {
expect(esc('')).to.equal('<a href="x">');
});
it('leaves plain text without HTML-significant characters unchanged (negative)', function() {
expect(esc('just plain text 123')).to.equal('just plain text 123');
});
it('leaves an empty string unchanged (negative)', function() {
expect(esc('')).to.equal('');
});
});