From 2fa6e1b0de58f0c2827843d0d1936cc493272c89 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 21 Aug 2019 17:47:16 +0300 Subject: [PATCH 1/2] anchor-markdown-headings.js: fix IDs to be unique. Changed anchor's `name` attribute to `id` since `name` is removed in HTML5. --- scripts/plugins/anchor-markdown-headings.js | 10 +++--- tests/scripts/anchor-mardown-headings.test.js | 33 +++++++++++++++---- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/scripts/plugins/anchor-markdown-headings.js b/scripts/plugins/anchor-markdown-headings.js index 9a1e3ffa6bb17..9bdcaa90f555f 100644 --- a/scripts/plugins/anchor-markdown-headings.js +++ b/scripts/plugins/anchor-markdown-headings.js @@ -12,7 +12,7 @@ * `` to quote your English anchor name inside, with your * own title beside it. */ -module.exports = function anchorMarkdownHeadings (text, level, raw) { +module.exports = function anchorMarkdownHeadings (text, level, raw, slugger) { // Check whether we've got the comment matches // , and even // (20 hex = 32 dec = space character) @@ -42,8 +42,8 @@ module.exports = function anchorMarkdownHeadings (text, level, raw) { anchorTitle = anchorTitle.toLowerCase() - return '' + text + '' + const anchorId = `${slugger ? slugger.slug(anchorTitle) : anchorTitle}` + const headerId = `header-${anchorId}` + + return `${text}` } diff --git a/tests/scripts/anchor-mardown-headings.test.js b/tests/scripts/anchor-mardown-headings.test.js index 98788386ef1f6..ee04cd57ca6b5 100644 --- a/tests/scripts/anchor-mardown-headings.test.js +++ b/tests/scripts/anchor-mardown-headings.test.js @@ -1,10 +1,11 @@ 'use strict' +const marked = require('marked') const test = require('tape') const anchorMarkdownHeadings = require('../../scripts/plugins/anchor-markdown-headings') test('anchorMarkdownHeadings', (t) => { - t.plan(6) + t.plan(7) t.test('correctly parses markdown heading without links', (t) => { const text = 'Simple title' @@ -12,8 +13,8 @@ test('anchorMarkdownHeadings', (t) => { const raw = 'Simple title' const output = anchorMarkdownHeadings(text, level, raw) const expected = '

Simple title' + - '

' + '' t.plan(1) t.equal(output, expected) @@ -26,7 +27,7 @@ test('anchorMarkdownHeadings', (t) => { const output = anchorMarkdownHeadings(text, level, raw) const expected = '' t.plan(1) @@ -40,7 +41,7 @@ test('anchorMarkdownHeadings', (t) => { const output = anchorMarkdownHeadings(text, level, raw) const expected = '

a b c' + 'de' + - '

' t.plan(1) @@ -53,7 +54,7 @@ test('anchorMarkdownHeadings', (t) => { const raw = '$$$ WIN BIG! $$$' const output = anchorMarkdownHeadings(text, level, raw) const expected = '

$$$ WIN BIG! $$$' + - '

' t.plan(1) @@ -67,7 +68,8 @@ test('anchorMarkdownHeadings', (t) => { const output = anchorMarkdownHeadings(text, level, raw) const expected = '

' + '这是链接测试!' + - '

' t.plan(1) @@ -84,4 +86,21 @@ test('anchorMarkdownHeadings', (t) => { t.plan(1) t.equal(output, expected) }) + + t.test('does not generate duplicate IDs', (t) => { + const renderer = new marked.Renderer() + renderer.heading = anchorMarkdownHeadings + + const text = '# Title\n# Title' + const output = marked(text, { renderer: renderer }) + const expected = '

Title' + + '

' + + '

Title' + + '

' + + t.plan(1) + t.equal(output, expected) + }) }) From af482f476a94109220fb0fad6b317bf0571bf809 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Thu, 22 Aug 2019 13:29:12 +0300 Subject: [PATCH 2/2] Fix duplicate IDs in Italian buffer-constructor-deprecation.md. --- .../guides/buffer-constructor-deprecation.md | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/locale/it/docs/guides/buffer-constructor-deprecation.md b/locale/it/docs/guides/buffer-constructor-deprecation.md index 1bbdb0f0261f2..8fee9ee13d064 100644 --- a/locale/it/docs/guides/buffer-constructor-deprecation.md +++ b/locale/it/docs/guides/buffer-constructor-deprecation.md @@ -5,7 +5,6 @@ layout: docs.hbs # Porting to the `Buffer.from()`/`Buffer.alloc()` API - ## Overview This guide explains how to migrate to safe `Buffer` constructor methods. The migration fixes the following deprecation warning: @@ -60,8 +59,7 @@ There is a drawback, though, that it doesn't always overridden e.g. with a polyfill, so recommended is a combination of this and some other method described above. - -## Variant 1: Drop support for Node.js ≤ 4.4.x and 5.0.0 — 5.9.x +## Variant 1: Drop support for Node.js ≤ 4.4.x and 5.0.0 — 5.9.x This is the recommended solution nowadays that would imply only minimal overhead. @@ -91,8 +89,7 @@ or [Variant 3](#variant-3) on older branches, so people using those older branch the fix. That way, you will eradicate potential issues caused by unguarded `Buffer` API usage and your users will not observe a runtime deprecation warning when running your code on Node.js 10._ - -## Variant 2: Use a polyfill +## Variant 2: Use a polyfill There are three different polyfills available: @@ -136,8 +133,7 @@ is recommended. _Don't forget to drop the polyfill usage once you drop support for Node.js < 4.5.0._ - -## Variant 3 — Manual detection, with safeguards +## Variant 3 — Manual detection, with safeguards This is useful if you create `Buffer` instances in only a few places (e.g. one), or you have your own wrapper around them. @@ -223,11 +219,9 @@ leaking to the remote attacker. _Note that the same applies to `new Buffer()` usage without zero-filling, depending on the Node.js version (and lacking type checks also adds DoS to the list of potential problems)._ - ## FAQ - -### What is wrong with the `Buffer` constructor? +### What is wrong with the `Buffer` constructor? The `Buffer` constructor could be used to create a buffer in many different ways: @@ -280,8 +274,7 @@ When using `Buffer.from(req.body.string)` instead, passing a number will always throw an exception instead, giving a controlled behavior that can always be handled by the program. - -### The `Buffer()` constructor has been deprecated for a while. Is this really an issue? +### The `Buffer()` constructor has been deprecated for a while. Is this really an issue? Surveys of code in the `npm` ecosystem have shown that the `Buffer()` constructor is still widely used. This includes new code, and overall usage of such code has actually been