mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
- Markdown links from imported files (CodeQL #555): Plane escaped [ and ] in a link title but not backslash, so a title ending in "\" ran on into the URL, and its URL went through encodeURIComponent, which leaves ( and ) as they are, so a ")" ended the link early and the rest became a second link. ClickUp, Super Productivity and Vikunja wrote links the same way. All four now use models/lib/markdownLink.js, which escapes the title and percent-encodes what ends or breaks a destination. - A replacement of a space with itself in a test (CodeQL #554), where a regular-expression escape was meant. tests/noIdentityReplacement.test.cjs now also finds the regular-expression form of an identity replacement. - The vendored @wekanteam/exceljs (CodeQL #556-#558, Dependabot #137-#142): sheet names are read without a backtracking regular expression, the manual test pages pin their CDN script with Subresource Integrity, and brace-expansion is 5.0.12. Same change as the fork, .tools/exceljs 25db789. The vendored jade's dev tools also had brace-expansion 5.0.6. tests/securityAlerts20261010.test.cjs pins each, and the shape of each across the tree. Thanks to GitHub CodeQL, dependabot and xet7 !
28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
// A Markdown link written from text an import file supplies. Plain
|
|
// JavaScript, so the importers' Node tests run it.
|
|
//
|
|
// The title escapes backslash as well as [ and ]: escaping only the brackets
|
|
// left a title ending in "\" free to escape the closing bracket, so the title
|
|
// ran on into the link. The destination percent-encodes everything that ends
|
|
// it or breaks it - ( ) < > \, whitespace and control characters.
|
|
// encodeURIComponent was used for that before, and it leaves ( and ) as they
|
|
// are, so a ")" in a URL still closed the link early. The caller still decides
|
|
// which schemes may be linked at all.
|
|
|
|
const pct = c => {
|
|
const code = c.charCodeAt(0);
|
|
return code < 128 ? `%${code.toString(16).toUpperCase().padStart(2, '0')}` : encodeURIComponent(c);
|
|
};
|
|
|
|
export function markdownLinkTitle(text) {
|
|
return String(text == null ? '' : text).replace(/[\\[\]]/g, '\\$&');
|
|
}
|
|
|
|
export function markdownLinkUrl(url) {
|
|
return String(url == null ? '' : url).replace(/[()<>\\\s\u0000-\u001f\u007f]/gu, pct);
|
|
}
|
|
|
|
export function markdownLink(title, url) {
|
|
return `[${markdownLinkTitle(title)}](${markdownLinkUrl(url)})`;
|
|
}
|