3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-20 07:05:44 +01:00

Write a URL as the ADF holds it, whatever its scheme; file item 142 to weigh carrying script URLs

This commit is contained in:
2026-10-23 13:43:01 +02:00
committed by Lillem4n
parent 6fe36d5947
commit cc029b0bc9
8 changed files with 42 additions and 39 deletions
+2 -5
View File
@@ -209,12 +209,9 @@ function writableText(node: AdfNode): node is AdfNode & { text: string } {
return typeof node.text === 'string' && node.text !== '' && !node.text.includes('\0')
}
// cmark's dangerous-URL rule: its schemes and its safe image data. A browser drops tabs and line breaks and a leading control or space before it reads the scheme, so the check does too.
// Any scheme, `javascript:` included, as the ADF holds it: docs/decisions.md §HTML writes a URL as the ADF holds it, whatever its scheme.
function writableUrl(url: string): boolean {
if (url.includes('\0')) return false
const scheme = url.replace(/[\t\n\r]/g, '').replace(/^[\u0001- ]+/, '').toLowerCase()
if (/^(?:file|javascript|vbscript):/.test(scheme)) return false
return !scheme.startsWith('data:') || /^data:image\/(?:gif|jpeg|png|webp)/.test(scheme)
return !url.includes('\0')
}
function carriedBlock(node: AdfNode, path: ConvertErrorPath, depth: number): Result<string> {