Add page data delivery and publication guards
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
injectBeforeDocumentClosingBody,
|
||||
injectBeforeDocumentClosingHead,
|
||||
} from './html-document-injection.mjs';
|
||||
|
||||
test('injectBeforeDocumentClosingBody skips </body> inside inline scripts', () => {
|
||||
const html = `<html><body>
|
||||
<script>
|
||||
var x='<html><body>'+tb+'</body></html>';
|
||||
</script>
|
||||
<p>content</p>
|
||||
</body></html>`;
|
||||
const result = injectBeforeDocumentClosingBody(html, '<footer>brand</footer>\n');
|
||||
assert.match(result, /\+tb\+'<\/body><\/html>'/);
|
||||
assert.match(result, /<footer>brand<\/footer>\s*<\/body><\/html>$/);
|
||||
assert.equal((result.match(/<\/body>/gi) ?? []).length, 2);
|
||||
});
|
||||
|
||||
test('injectBeforeDocumentClosingHead uses the last </head>', () => {
|
||||
const html = `<html><head><title>x</title></head><body>
|
||||
<script>var h='</head>';</script>
|
||||
</body></html>`;
|
||||
const result = injectBeforeDocumentClosingHead(html, '<style>body{}</style>\n');
|
||||
assert.match(result, /var h='<\/head>'/);
|
||||
assert.match(result, /<style>body\{\}<\/style>\s*<\/head><body>/);
|
||||
});
|
||||
Reference in New Issue
Block a user