katex 0.16.19 → 0.16.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/katex.mjs CHANGED
@@ -3942,10 +3942,20 @@ var toNode = function toNode(tagName) {
3942
3942
  return node;
3943
3943
  };
3944
3944
  /**
3945
- * Convert into an HTML markup string
3945
+ * https://w3c.github.io/html-reference/syntax.html#syntax-attributes
3946
+ *
3947
+ * > Attribute Names must consist of one or more characters
3948
+ * other than the space characters, U+0000 NULL,
3949
+ * '"', "'", ">", "/", "=", the control characters,
3950
+ * and any characters that are not defined by Unicode.
3946
3951
  */
3947
3952
 
3948
3953
 
3954
+ var invalidAttributeNameRegex = /[\s"'>/=\x00-\x1f]/;
3955
+ /**
3956
+ * Convert into an HTML markup string
3957
+ */
3958
+
3949
3959
  var toMarkup = function toMarkup(tagName) {
3950
3960
  var markup = "<" + tagName; // Add the class
3951
3961
 
@@ -3968,6 +3978,10 @@ var toMarkup = function toMarkup(tagName) {
3968
3978
 
3969
3979
  for (var attr in this.attributes) {
3970
3980
  if (this.attributes.hasOwnProperty(attr)) {
3981
+ if (invalidAttributeNameRegex.test(attr)) {
3982
+ throw new ParseError("Invalid attribute name '" + attr + "'");
3983
+ }
3984
+
3971
3985
  markup += " " + attr + "=\"" + utils.escape(this.attributes[attr]) + "\"";
3972
3986
  }
3973
3987
  }
@@ -15375,7 +15389,7 @@ defineMacro("\\char", function (context) {
15375
15389
  // \renewcommand{\macro}[args]{definition}
15376
15390
  // TODO: Optional arguments: \newcommand{\macro}[args][default]{definition}
15377
15391
 
15378
- var newcommand = (context, existsOK, nonexistsOK) => {
15392
+ var newcommand = (context, existsOK, nonexistsOK, skipIfExists) => {
15379
15393
  var arg = context.consumeArg().tokens;
15380
15394
 
15381
15395
  if (arg.length !== 1) {
@@ -15412,19 +15426,22 @@ var newcommand = (context, existsOK, nonexistsOK) => {
15412
15426
 
15413
15427
  numArgs = parseInt(argText);
15414
15428
  arg = context.consumeArg().tokens;
15415
- } // Final arg is the expansion of the macro
15429
+ }
15416
15430
 
15431
+ if (!(exists && skipIfExists)) {
15432
+ // Final arg is the expansion of the macro
15433
+ context.macros.set(name, {
15434
+ tokens: arg,
15435
+ numArgs
15436
+ });
15437
+ }
15417
15438
 
15418
- context.macros.set(name, {
15419
- tokens: arg,
15420
- numArgs
15421
- });
15422
15439
  return '';
15423
15440
  };
15424
15441
 
15425
- defineMacro("\\newcommand", context => newcommand(context, false, true));
15426
- defineMacro("\\renewcommand", context => newcommand(context, true, false));
15427
- defineMacro("\\providecommand", context => newcommand(context, true, true)); // terminal (console) tools
15442
+ defineMacro("\\newcommand", context => newcommand(context, false, true, false));
15443
+ defineMacro("\\renewcommand", context => newcommand(context, true, false, false));
15444
+ defineMacro("\\providecommand", context => newcommand(context, true, true, true)); // terminal (console) tools
15428
15445
 
15429
15446
  defineMacro("\\message", context => {
15430
15447
  var arg = context.consumeArgs(1)[0]; // eslint-disable-next-line no-console
@@ -18413,7 +18430,7 @@ var renderToHTMLTree = function renderToHTMLTree(expression, options) {
18413
18430
  }
18414
18431
  };
18415
18432
 
18416
- var version = "0.16.19";
18433
+ var version = "0.16.21";
18417
18434
  var __domTree = {
18418
18435
  Span,
18419
18436
  Anchor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "katex",
3
- "version": "0.16.19",
3
+ "version": "0.16.21",
4
4
  "description": "Fast math typesetting for the web.",
5
5
  "main": "dist/katex.js",
6
6
  "exports": {
package/src/domTree.js CHANGED
@@ -17,6 +17,7 @@ import {path} from "./svgGeometry";
17
17
  import type Options from "./Options";
18
18
  import {DocumentFragment} from "./tree";
19
19
  import {makeEm} from "./units";
20
+ import ParseError from "./ParseError";
20
21
 
21
22
  import type {VirtualNode} from "./tree";
22
23
 
@@ -83,6 +84,16 @@ const toNode = function(tagName: string): HTMLElement {
83
84
  return node;
84
85
  };
85
86
 
87
+ /**
88
+ * https://w3c.github.io/html-reference/syntax.html#syntax-attributes
89
+ *
90
+ * > Attribute Names must consist of one or more characters
91
+ * other than the space characters, U+0000 NULL,
92
+ * '"', "'", ">", "/", "=", the control characters,
93
+ * and any characters that are not defined by Unicode.
94
+ */
95
+ const invalidAttributeNameRegex = /[\s"'>/=\x00-\x1f]/;
96
+
86
97
  /**
87
98
  * Convert into an HTML markup string
88
99
  */
@@ -110,6 +121,9 @@ const toMarkup = function(tagName: string): string {
110
121
  // Add the attributes
111
122
  for (const attr in this.attributes) {
112
123
  if (this.attributes.hasOwnProperty(attr)) {
124
+ if (invalidAttributeNameRegex.test(attr)) {
125
+ throw new ParseError(`Invalid attribute name '${attr}'`);
126
+ }
113
127
  markup += ` ${attr}="${utils.escape(this.attributes[attr])}"`;
114
128
  }
115
129
  }
package/src/macros.js CHANGED
@@ -146,7 +146,9 @@ defineMacro("\\char", function(context) {
146
146
  // \newcommand{\macro}[args]{definition}
147
147
  // \renewcommand{\macro}[args]{definition}
148
148
  // TODO: Optional arguments: \newcommand{\macro}[args][default]{definition}
149
- const newcommand = (context, existsOK: boolean, nonexistsOK: boolean) => {
149
+ const newcommand = (
150
+ context, existsOK: boolean, nonexistsOK: boolean, skipIfExists: boolean
151
+ ) => {
150
152
  let arg = context.consumeArg().tokens;
151
153
  if (arg.length !== 1) {
152
154
  throw new ParseError(
@@ -181,16 +183,21 @@ const newcommand = (context, existsOK: boolean, nonexistsOK: boolean) => {
181
183
  arg = context.consumeArg().tokens;
182
184
  }
183
185
 
184
- // Final arg is the expansion of the macro
185
- context.macros.set(name, {
186
- tokens: arg,
187
- numArgs,
188
- });
186
+ if (!(exists && skipIfExists)) {
187
+ // Final arg is the expansion of the macro
188
+ context.macros.set(name, {
189
+ tokens: arg,
190
+ numArgs,
191
+ });
192
+ }
189
193
  return '';
190
194
  };
191
- defineMacro("\\newcommand", (context) => newcommand(context, false, true));
192
- defineMacro("\\renewcommand", (context) => newcommand(context, true, false));
193
- defineMacro("\\providecommand", (context) => newcommand(context, true, true));
195
+ defineMacro("\\newcommand",
196
+ (context) => newcommand(context, false, true, false));
197
+ defineMacro("\\renewcommand",
198
+ (context) => newcommand(context, true, false, false));
199
+ defineMacro("\\providecommand",
200
+ (context) => newcommand(context, true, true, true));
194
201
 
195
202
  // terminal (console) tools
196
203
  defineMacro("\\message", (context) => {