mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
fix: fix infinite loop for indented code blank line (#3947)
* fix: fix infinite loop for indented code blank line * set redos tests to not silent * simplify test * fix test
This commit is contained in:
+29
-14
@@ -110,7 +110,15 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
|
||||
src = src.replace(other.tabCharGlobal, ' ').replace(other.spaceLine, '');
|
||||
}
|
||||
|
||||
let srcLength = Infinity;
|
||||
while (src) {
|
||||
if (src.length < srcLength) {
|
||||
srcLength = src.length;
|
||||
} else {
|
||||
this.infiniteLoopError(src.charCodeAt(0));
|
||||
break;
|
||||
}
|
||||
|
||||
let token: Tokens.Generic | undefined;
|
||||
|
||||
if (this.options.extensions?.block?.some((extTokenizer) => {
|
||||
@@ -275,13 +283,8 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
|
||||
}
|
||||
|
||||
if (src) {
|
||||
const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
|
||||
if (this.options.silent) {
|
||||
console.error(errMsg);
|
||||
break;
|
||||
} else {
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
this.infiniteLoopError(src.charCodeAt(0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,7 +337,15 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
|
||||
|
||||
let keepPrevChar = false;
|
||||
let prevChar = '';
|
||||
let srcLength = Infinity;
|
||||
while (src) {
|
||||
if (src.length < srcLength) {
|
||||
srcLength = src.length;
|
||||
} else {
|
||||
this.infiniteLoopError(src.charCodeAt(0));
|
||||
break;
|
||||
}
|
||||
|
||||
if (!keepPrevChar) {
|
||||
prevChar = '';
|
||||
}
|
||||
@@ -464,16 +475,20 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
|
||||
}
|
||||
|
||||
if (src) {
|
||||
const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
|
||||
if (this.options.silent) {
|
||||
console.error(errMsg);
|
||||
break;
|
||||
} else {
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
this.infiniteLoopError(src.charCodeAt(0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
private infiniteLoopError(byte: number) {
|
||||
const errMsg = 'Infinite loop on byte: ' + byte;
|
||||
if (this.options.silent) {
|
||||
console.error(errMsg);
|
||||
} else {
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ export function rtrim(str: string, c: string, invert?: boolean) {
|
||||
export function trimTrailingBlankLines(str: string) {
|
||||
const lines = str.split('\n');
|
||||
let end = lines.length - 1;
|
||||
while (end >= 0 && !lines[end].trim()) {
|
||||
while (end >= 0 && other.blankLine.test(lines[end])) {
|
||||
end--;
|
||||
}
|
||||
if (lines.length - end <= 2) {
|
||||
|
||||
Vendored
+1
@@ -47,4 +47,5 @@ runTests({
|
||||
runTests({
|
||||
tests: redosTests,
|
||||
parse,
|
||||
defaultMarkedOptions: { silent: false },
|
||||
});
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
markdown: '\t\v\n',
|
||||
html: '<pre><code>\v</code></pre>\n',
|
||||
};
|
||||
Reference in New Issue
Block a user