repositories

daemon-sec-lotl

DÆMONBins: GTFOBins × LOLBAS × WADComs × LOOBins in one filterable catalog

clonegit clone https://git.daemon-sec.xyz/daemon-sec-lotl.git
highlight.test.mjsJavaScript31 lines1.3 KiBraw download
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { loadTs } from './_loadts.mjs';

const { escapeHtml, highlightCommand } = await loadTs('src/lib/highlight.ts');

test('escapeHtml neutralises markup and attribute delimiters', () => {
  const out = escapeHtml('<b onclick="x">&</b>');
  assert.ok(!out.includes('<'));
  assert.ok(!out.includes('>'));
  assert.ok(!out.includes('"'));
  assert.equal(out, '&lt;b onclick=&quot;x&quot;&gt;&amp;&lt;/b&gt;');
  assert.equal(escapeHtml(123), '123');
});

test('highlightCommand never emits raw input markup', () => {
  const out = highlightCommand('echo <script>alert(1)</script> "a<b"');
  assert.ok(!/<script/.test(out));
  assert.ok(!out.includes('a<b'));
  assert.ok(out.includes('&lt;script&gt;'));
});

test('highlightCommand token classes', () => {
  const out = highlightCommand('sudo tar -cf /dev/null 10.10.10.10 | sh');
  assert.match(out, /<span class="tk-cmd">sudo<\/span>/);
  assert.match(out, /<span class="tk-flag">-cf<\/span>/);
  assert.match(out, /<span class="tk-num">10\.10\.10\.10<\/span>/);
  assert.match(out, /<span class="tk-op">\|<\/span>/);
  assert.equal(highlightCommand('# a comment'), '<span class="tk-muted"># a comment</span>');
  assert.equal(highlightCommand('a\nb').split('\n').length, 2);
});