Skip to content

176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.

fix: keep links inside parentheses intact while blocking unsafe link schemes

matinfb5ef680904c
diff --git a/assets/js/handbook.js b/assets/js/handbook.js
index b5a5aca1..4feb4d82 100644
--- a/assets/js/handbook.js
+++ b/assets/js/handbook.js
@@ -37,7 +37,7 @@
function inline(md) {
return escapeHtml(md)
.replace(/`([^`]+)`/g, '$1')
- .replace(/\[([^\]]+)\]\(([^\s]+)\)/g, function (m, label, href) {
+ .replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, function (m, label, href) {
return isSafeHref(href) ? '<a href="' + href + '">' + label + '</a>' : label;
})
.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
diff --git a/tests/handbook.test.js b/tests/handbook.test.js
index abb7c733..cf6eea06 100644
--- a/tests/handbook.test.js
+++ b/tests/handbook.test.js
@@ -19,10 +19,11 @@ test('inline shows code as plain text and renders links, bold and italics', () =
});
test('inline only links relative, anchor and http(s) URLs', () => {
- assert.equal(HB.inline('[x](javascript:alert(1))'), 'x');
+ assert.ok(!HB.inline('[x](javascript:alert(1))').includes('<a'), 'no link for javascript: URLs');
assert.equal(HB.inline('[a](https://example.com/p)'), '<a href="https://example.com/p">a</a>');
assert.equal(HB.inline('[b](#top)'), '<a href="#top">b</a>');
assert.equal(HB.inline('[c](../scale-in/)'), '<a href="../scale-in/">c</a>');
+ assert.equal(HB.inline('(see [Scale In](../scale-in/))'), '(see <a href="../scale-in/">Scale In</a>)');
});
test('sections splits a README by its ## headings', () => {