Spaces:
Running
Running
File size: 967 Bytes
2abf76f | 1 2 3 4 5 6 7 8 9 10 11 12 13 | import test from 'node:test';
import assert from 'node:assert/strict';
import {JSDOM} from 'jsdom';
import {highlightPython} from '../src/python-highlight.ts';
test('Python markup preserves the program and never turns source strings into active HTML',()=>{
const source='import sand3d as s3d\n# dimensions\ndef make(w=12.5):\n text = """</code><img src=x onerror=alert(1)>\n<script>alert(2)</script>&"""\n return s3d.box("part", w, 3, 4)\n';
const dom=new JSDOM('<pre><code></code></pre>'),code=dom.window.document.querySelector('code');
code.innerHTML=highlightPython(source);assert.equal(code.textContent,source);
assert(code.querySelector('.hljs-keyword'));assert(code.querySelector('.hljs-string'));assert(code.querySelector('.hljs-number'));assert(code.querySelector('.hljs-comment'));
assert.equal(code.querySelectorAll('script,img,a,iframe').length,0);assert([...code.querySelectorAll('*')].every(el=>el.tagName==='SPAN'));
dom.window.close();
});
|