mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
348 lines
10 KiB
Diff
348 lines
10 KiB
Diff
diff --git a/src/Lexer.js b/src/Lexer.js
|
|
--- a/src/Lexer.js
|
|
+++ b/src/Lexer.js
|
|
@@ -6,5 +6,5 @@ const { repeatString } = require('./helpers.js');
|
|
/**
|
|
* smartypants text replacement
|
|
- */
|
|
+ *
|
|
function smartypants(text) {
|
|
return text
|
|
@@ -27,5 +27,5 @@ function smartypants(text) {
|
|
/**
|
|
* mangle email addresses
|
|
- */
|
|
+ *
|
|
function mangle(text) {
|
|
let out = '',
|
|
@@ -465,5 +465,5 @@ module.exports = class Lexer {
|
|
|
|
// autolink
|
|
- if (token = this.tokenizer.autolink(src, mangle)) {
|
|
+ if (token = this.tokenizer.autolink(src)) {
|
|
src = src.substring(token.raw.length);
|
|
tokens.push(token);
|
|
@@ -472,5 +472,5 @@ module.exports = class Lexer {
|
|
|
|
// url (gfm)
|
|
- if (!this.state.inLink && (token = this.tokenizer.url(src, mangle))) {
|
|
+ if (!this.state.inLink && (token = this.tokenizer.url(src))) {
|
|
src = src.substring(token.raw.length);
|
|
tokens.push(token);
|
|
@@ -493,5 +493,5 @@ module.exports = class Lexer {
|
|
}
|
|
}
|
|
- if (token = this.tokenizer.inlineText(cutSrc, smartypants)) {
|
|
+ if (token = this.tokenizer.inlineText(cutSrc)) {
|
|
src = src.substring(token.raw.length);
|
|
this.ln = token.ln || this.ln;
|
|
diff --git a/src/Renderer.js b/src/Renderer.js
|
|
--- a/src/Renderer.js
|
|
+++ b/src/Renderer.js
|
|
@@ -142,5 +142,5 @@ module.exports = class Renderer {
|
|
|
|
link(href, title, text) {
|
|
- href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
+ href = cleanUrl(this.options.baseUrl, href);
|
|
if (href === null) {
|
|
return text;
|
|
@@ -155,5 +155,5 @@ module.exports = class Renderer {
|
|
|
|
image(href, title, text) {
|
|
- href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
+ href = cleanUrl(this.options.baseUrl, href);
|
|
if (href === null) {
|
|
return text;
|
|
diff --git a/src/Tokenizer.js b/src/Tokenizer.js
|
|
--- a/src/Tokenizer.js
|
|
+++ b/src/Tokenizer.js
|
|
@@ -321,14 +321,7 @@ module.exports = class Tokenizer {
|
|
type: 'html',
|
|
raw: cap[0],
|
|
- pre: !this.options.sanitizer
|
|
- && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
|
|
+ pre: (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
|
|
text: cap[0]
|
|
};
|
|
- if (this.options.sanitize) {
|
|
- token.type = 'paragraph';
|
|
- token.text = this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]);
|
|
- token.tokens = [];
|
|
- this.lexer.inline(token.text, token.tokens);
|
|
- }
|
|
return token;
|
|
}
|
|
@@ -477,15 +470,9 @@ module.exports = class Tokenizer {
|
|
|
|
return {
|
|
- type: this.options.sanitize
|
|
- ? 'text'
|
|
- : 'html',
|
|
+ type: 'html',
|
|
raw: cap[0],
|
|
inLink: this.lexer.state.inLink,
|
|
inRawBlock: this.lexer.state.inRawBlock,
|
|
- text: this.options.sanitize
|
|
- ? (this.options.sanitizer
|
|
- ? this.options.sanitizer(cap[0])
|
|
- : escape(cap[0]))
|
|
- : cap[0]
|
|
+ text: cap[0]
|
|
};
|
|
}
|
|
@@ -672,10 +659,10 @@ module.exports = class Tokenizer {
|
|
}
|
|
|
|
- autolink(src, mangle) {
|
|
+ autolink(src) {
|
|
const cap = this.rules.inline.autolink.exec(src);
|
|
if (cap) {
|
|
let text, href;
|
|
if (cap[2] === '@') {
|
|
- text = escape(this.options.mangle ? mangle(cap[1]) : cap[1]);
|
|
+ text = escape(cap[1]);
|
|
href = 'mailto:' + text;
|
|
} else {
|
|
@@ -700,10 +687,10 @@ module.exports = class Tokenizer {
|
|
}
|
|
|
|
- url(src, mangle) {
|
|
+ url(src) {
|
|
let cap;
|
|
if (cap = this.rules.inline.url.exec(src)) {
|
|
let text, href;
|
|
if (cap[2] === '@') {
|
|
- text = escape(this.options.mangle ? mangle(cap[0]) : cap[0]);
|
|
+ text = escape(cap[0]);
|
|
href = 'mailto:' + text;
|
|
} else {
|
|
@@ -737,12 +724,12 @@ module.exports = class Tokenizer {
|
|
}
|
|
|
|
- inlineText(src, smartypants) {
|
|
+ inlineText(src) {
|
|
const cap = this.rules.inline.text.exec(src);
|
|
if (cap) {
|
|
let text;
|
|
if (this.lexer.state.inRawBlock) {
|
|
- text = this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0])) : cap[0];
|
|
+ text = cap[0];
|
|
} else {
|
|
- text = escape(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
|
|
+ text = escape(cap[0]);
|
|
}
|
|
return {
|
|
diff --git a/src/defaults.js b/src/defaults.js
|
|
--- a/src/defaults.js
|
|
+++ b/src/defaults.js
|
|
@@ -9,12 +9,8 @@ function getDefaults() {
|
|
highlight: null,
|
|
langPrefix: 'language-',
|
|
- mangle: true,
|
|
pedantic: false,
|
|
renderer: null,
|
|
- sanitize: false,
|
|
- sanitizer: null,
|
|
silent: false,
|
|
smartLists: false,
|
|
- smartypants: false,
|
|
tokenizer: null,
|
|
walkTokens: null,
|
|
diff --git a/src/helpers.js b/src/helpers.js
|
|
--- a/src/helpers.js
|
|
+++ b/src/helpers.js
|
|
@@ -64,18 +64,5 @@ function edit(regex, opt) {
|
|
const nonWordAndColonTest = /[^\w:]/g;
|
|
const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
|
|
-function cleanUrl(sanitize, base, href) {
|
|
- if (sanitize) {
|
|
- let prot;
|
|
- try {
|
|
- prot = decodeURIComponent(unescape(href))
|
|
- .replace(nonWordAndColonTest, '')
|
|
- .toLowerCase();
|
|
- } catch (e) {
|
|
- return null;
|
|
- }
|
|
- if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
|
|
- return null;
|
|
- }
|
|
- }
|
|
+function cleanUrl(base, href) {
|
|
if (base && !originIndependentUrl.test(href)) {
|
|
href = resolveUrl(base, href);
|
|
@@ -227,10 +214,4 @@ function findClosingBracket(str, b) {
|
|
}
|
|
|
|
-function checkSanitizeDeprecation(opt) {
|
|
- if (opt && opt.sanitize && !opt.silent) {
|
|
- console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options');
|
|
- }
|
|
-}
|
|
-
|
|
// copied from https://stackoverflow.com/a/5450113/806777
|
|
function repeatString(pattern, count) {
|
|
@@ -260,5 +241,4 @@ module.exports = {
|
|
rtrim,
|
|
findClosingBracket,
|
|
- checkSanitizeDeprecation,
|
|
repeatString
|
|
};
|
|
diff --git a/src/marked.js b/src/marked.js
|
|
--- a/src/marked.js
|
|
+++ b/src/marked.js
|
|
@@ -7,5 +7,4 @@ const Slugger = require('./Slugger.js');
|
|
const {
|
|
merge,
|
|
- checkSanitizeDeprecation,
|
|
escape
|
|
} = require('./helpers.js');
|
|
@@ -35,5 +34,4 @@ function marked(src, opt, callback) {
|
|
|
|
opt = merge({}, marked.defaults, opt || {});
|
|
- checkSanitizeDeprecation(opt);
|
|
|
|
if (callback) {
|
|
@@ -302,5 +300,4 @@ marked.parseInline = function(src, opt) {
|
|
|
|
opt = merge({}, marked.defaults, opt || {});
|
|
- checkSanitizeDeprecation(opt);
|
|
|
|
try {
|
|
@@ -311,5 +308,5 @@ marked.parseInline = function(src, opt) {
|
|
return Parser.parseInline(tokens, opt);
|
|
} catch (e) {
|
|
- e.message += '\nPlease report this to https://github.com/markedjs/marked.';
|
|
+ e.message += '\nmake issue @ https://github.com/9001/copyparty';
|
|
if (opt.silent) {
|
|
return '<p>An error occurred:</p><pre>'
|
|
diff --git a/test/bench.js b/test/bench.js
|
|
--- a/test/bench.js
|
|
+++ b/test/bench.js
|
|
@@ -33,5 +33,4 @@ async function runBench(options) {
|
|
breaks: false,
|
|
pedantic: false,
|
|
- sanitize: false,
|
|
smartLists: false
|
|
});
|
|
@@ -45,5 +44,4 @@ async function runBench(options) {
|
|
breaks: false,
|
|
pedantic: false,
|
|
- sanitize: false,
|
|
smartLists: false
|
|
});
|
|
@@ -58,5 +56,4 @@ async function runBench(options) {
|
|
breaks: false,
|
|
pedantic: false,
|
|
- sanitize: false,
|
|
smartLists: false
|
|
});
|
|
@@ -70,5 +67,4 @@ async function runBench(options) {
|
|
breaks: false,
|
|
pedantic: false,
|
|
- sanitize: false,
|
|
smartLists: false
|
|
});
|
|
@@ -83,5 +79,4 @@ async function runBench(options) {
|
|
breaks: false,
|
|
pedantic: true,
|
|
- sanitize: false,
|
|
smartLists: false
|
|
});
|
|
@@ -95,5 +90,4 @@ async function runBench(options) {
|
|
breaks: false,
|
|
pedantic: true,
|
|
- sanitize: false,
|
|
smartLists: false
|
|
});
|
|
diff --git a/test/specs/run-spec.js b/test/specs/run-spec.js
|
|
--- a/test/specs/run-spec.js
|
|
+++ b/test/specs/run-spec.js
|
|
@@ -22,9 +22,4 @@ function runSpecs(title, dir, showCompletionTable, options) {
|
|
}
|
|
|
|
- if (spec.options.sanitizer) {
|
|
- // eslint-disable-next-line no-eval
|
|
- spec.options.sanitizer = eval(spec.options.sanitizer);
|
|
- }
|
|
-
|
|
(spec.only ? fit : (spec.skip ? xit : it))('should ' + passFail + example, async() => {
|
|
const before = process.hrtime();
|
|
@@ -53,3 +48,2 @@ runSpecs('Original', './original', false, { gfm: false, pedantic: true });
|
|
runSpecs('New', './new');
|
|
runSpecs('ReDOS', './redos');
|
|
-runSpecs('Security', './security', false, { silent: true }); // silent - do not show deprecation warning
|
|
diff --git a/test/unit/Lexer-spec.js b/test/unit/Lexer-spec.js
|
|
--- a/test/unit/Lexer-spec.js
|
|
+++ b/test/unit/Lexer-spec.js
|
|
@@ -589,5 +589,5 @@ paragraph
|
|
});
|
|
|
|
- it('sanitize', () => {
|
|
+ /*it('sanitize', () => {
|
|
expectTokens({
|
|
md: '<div>html</div>',
|
|
@@ -607,5 +607,5 @@ paragraph
|
|
]
|
|
});
|
|
- });
|
|
+ });*/
|
|
});
|
|
|
|
@@ -652,5 +652,5 @@ paragraph
|
|
});
|
|
|
|
- it('html sanitize', () => {
|
|
+ /*it('html sanitize', () => {
|
|
expectInlineTokens({
|
|
md: '<div>html</div>',
|
|
@@ -660,5 +660,5 @@ paragraph
|
|
]
|
|
});
|
|
- });
|
|
+ });*/
|
|
|
|
it('link', () => {
|
|
@@ -971,5 +971,5 @@ paragraph
|
|
});
|
|
|
|
- it('autolink mangle email', () => {
|
|
+ /*it('autolink mangle email', () => {
|
|
expectInlineTokens({
|
|
md: '<test@example.com>',
|
|
@@ -991,5 +991,5 @@ paragraph
|
|
]
|
|
});
|
|
- });
|
|
+ });*/
|
|
|
|
it('url', () => {
|
|
@@ -1028,5 +1028,5 @@ paragraph
|
|
});
|
|
|
|
- it('url mangle email', () => {
|
|
+ /*it('url mangle email', () => {
|
|
expectInlineTokens({
|
|
md: 'test@example.com',
|
|
@@ -1048,5 +1048,5 @@ paragraph
|
|
]
|
|
});
|
|
- });
|
|
+ });*/
|
|
});
|
|
|
|
@@ -1064,5 +1064,5 @@ paragraph
|
|
});
|
|
|
|
- describe('smartypants', () => {
|
|
+ /*describe('smartypants', () => {
|
|
it('single quotes', () => {
|
|
expectInlineTokens({
|
|
@@ -1134,5 +1134,5 @@ paragraph
|
|
});
|
|
});
|
|
- });
|
|
+ });*/
|
|
});
|
|
});
|