mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-09 13:08:40 +00:00
Fix delimiter error message (#2186)
* Fix delimiter error message Avoid "circular structure" error message by avoiding JSON.stringify on a parse structure when getting an invalid delimiter type (e.g. ordgroup). Instead, report type of delimiter when it's invalid. Fixes #2184. * Fix and add tests
This commit is contained in:
@@ -62,11 +62,12 @@ function checkDelimiter(
|
|||||||
const symDelim = checkSymbolNodeType(delim);
|
const symDelim = checkSymbolNodeType(delim);
|
||||||
if (symDelim && utils.contains(delimiters, symDelim.text)) {
|
if (symDelim && utils.contains(delimiters, symDelim.text)) {
|
||||||
return symDelim;
|
return symDelim;
|
||||||
} else {
|
} else if (symDelim) {
|
||||||
throw new ParseError(
|
throw new ParseError(
|
||||||
"Invalid delimiter: '" +
|
`Invalid delimiter '${symDelim.text}' after '${context.funcName}'`,
|
||||||
(symDelim ? symDelim.text : JSON.stringify(delim)) +
|
delim);
|
||||||
"' after '" + context.funcName + "'", delim);
|
} else {
|
||||||
|
throw new ParseError(`Invalid delimiter type '${delim.type}'`, delim);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -250,14 +250,24 @@ describe("functions.js:", function() {
|
|||||||
describe("delimiter functions", function() {
|
describe("delimiter functions", function() {
|
||||||
it("reject invalid opening delimiters", function() {
|
it("reject invalid opening delimiters", function() {
|
||||||
expect`\bigl 1 + 2 \bigr`.toFailWithParseError(
|
expect`\bigl 1 + 2 \bigr`.toFailWithParseError(
|
||||||
"Invalid delimiter: '1' after '\\bigl' at position 7:" +
|
"Invalid delimiter '1' after '\\bigl' at position 7:" +
|
||||||
" \\bigl 1̲ + 2 \\bigr");
|
" \\bigl 1̲ + 2 \\bigr");
|
||||||
});
|
});
|
||||||
it("reject invalid closing delimiters", function() {
|
it("reject invalid closing delimiters", function() {
|
||||||
expect`\bigl(1+2\bigr=3`.toFailWithParseError(
|
expect`\bigl(1+2\bigr=3`.toFailWithParseError(
|
||||||
"Invalid delimiter: '=' after '\\bigr' at position 15:" +
|
"Invalid delimiter '=' after '\\bigr' at position 15:" +
|
||||||
" \\bigl(1+2\\bigr=̲3");
|
" \\bigl(1+2\\bigr=̲3");
|
||||||
});
|
});
|
||||||
|
it("reject group opening delimiters", function() {
|
||||||
|
expect`\bigl{(}1+2\bigr)3`.toFailWithParseError(
|
||||||
|
"Invalid delimiter type 'ordgroup' at position 6:" +
|
||||||
|
" \\bigl{̲(̲}̲1+2\\bigr)3");
|
||||||
|
});
|
||||||
|
it("reject group closing delimiters", function() {
|
||||||
|
expect`\bigl(1+2\bigr{)}3`.toFailWithParseError(
|
||||||
|
"Invalid delimiter type 'ordgroup' at position 15:" +
|
||||||
|
" \\bigl(1+2\\bigr{̲)̲}̲3");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("\\begin and \\end", function() {
|
describe("\\begin and \\end", function() {
|
||||||
|
Reference in New Issue
Block a user