Skip to content

Commit 1fb50b1

Browse files
committed
Merge branch 'develop' into v12
# Conflicts: # HISTORY.md
2 parents e3499a8 + f156a02 commit 1fb50b1

File tree

8 files changed

+360
-300
lines changed

8 files changed

+360
-300
lines changed

HISTORY.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
Thanks @gwhitney.
77

88

9-
# unpublished changes since 11.11.1
9+
# 2023-10-11, 11.11.2
1010

1111
- Fix #3025: improve handling of matrices and error handling
1212
in function `corr` (#3030). Thanks @vrushaket.
13+
- Fix #3074: improve error message when using function `max` in `derivative`.
14+
- Fix #3073: fix parsing quotes inside a string.
15+
- Fix #2027: cannot use named operators like `to` or `mod` as property name.
1316

1417

1518
# 2023-09-20, 11.11.1

package-lock.json

Lines changed: 288 additions & 277 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mathjs",
3-
"version": "11.11.1",
3+
"version": "11.11.2",
44
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
55
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
66
"homepage": "https://mathjs.org",
@@ -25,7 +25,7 @@
2525
"unit"
2626
],
2727
"dependencies": {
28-
"@babel/runtime": "^7.22.15",
28+
"@babel/runtime": "^7.23.1",
2929
"complex.js": "^2.1.1",
3030
"decimal.js": "^10.4.3",
3131
"escape-latex": "^1.2.0",
@@ -36,32 +36,32 @@
3636
"typed-function": "^4.1.1"
3737
},
3838
"devDependencies": {
39-
"@babel/core": "7.22.20",
39+
"@babel/core": "7.23.0",
4040
"@babel/plugin-transform-object-assign": "7.22.5",
4141
"@babel/plugin-transform-runtime": "7.22.15",
4242
"@babel/preset-env": "7.22.20",
4343
"@babel/register": "7.22.15",
44-
"@types/assert": "1.5.6",
45-
"@types/mocha": "10.0.1",
46-
"@typescript-eslint/eslint-plugin": "6.7.2",
47-
"@typescript-eslint/parser": "6.7.2",
44+
"@types/assert": "1.5.7",
45+
"@types/mocha": "10.0.2",
46+
"@typescript-eslint/eslint-plugin": "6.7.5",
47+
"@typescript-eslint/parser": "6.7.5",
4848
"assert": "2.1.0",
4949
"babel-loader": "9.1.3",
5050
"benchmark": "2.1.4",
5151
"c8": "8.0.1",
5252
"codecov": "3.8.3",
53-
"core-js": "3.32.2",
53+
"core-js": "3.33.0",
5454
"del": "6.1.1",
5555
"dtslint": "4.2.1",
56-
"eslint": "8.49.0",
56+
"eslint": "8.51.0",
5757
"eslint-config-prettier": "9.0.0",
5858
"eslint-config-standard": "17.1.0",
5959
"eslint-plugin-import": "2.28.1",
60-
"eslint-plugin-mocha": "10.1.0",
61-
"eslint-plugin-n": "16.1.0",
62-
"eslint-plugin-prettier": "5.0.0",
60+
"eslint-plugin-mocha": "10.2.0",
61+
"eslint-plugin-n": "16.2.0",
62+
"eslint-plugin-prettier": "5.0.1",
6363
"eslint-plugin-promise": "6.1.1",
64-
"expect-type": "0.16.0",
64+
"expect-type": "0.17.3",
6565
"expr-eval": "2.0.2",
6666
"fancy-log": "2.0.0",
6767
"glob": "8.1.0",

src/expression/parse.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,9 +1418,12 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({
14181418
// dot notation like variable.prop
14191419
getToken(state)
14201420

1421-
if (state.tokenType !== TOKENTYPE.SYMBOL) {
1421+
const isPropertyName = state.tokenType === TOKENTYPE.SYMBOL ||
1422+
(state.tokenType === TOKENTYPE.DELIMITER && state.token in NAMED_DELIMITERS)
1423+
if (!isPropertyName) {
14221424
throw createSyntaxError(state, 'Property name expected after dot')
14231425
}
1426+
14241427
params.push(new ConstantNode(state.token))
14251428
getToken(state)
14261429

@@ -1466,7 +1469,10 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({
14661469
if (currentCharacter(state) === '\\') {
14671470
// escape character, immediately process the next
14681471
// character to prevent stopping at a next '\"'
1469-
str += currentCharacter(state)
1472+
const cNext = nextCharacter(state)
1473+
if (cNext !== "'") {
1474+
str += currentCharacter(state)
1475+
}
14701476
next(state)
14711477
}
14721478

@@ -1517,7 +1523,10 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({
15171523
if (currentCharacter(state) === '\\') {
15181524
// escape character, immediately process the next
15191525
// character to prevent stopping at a next '\''
1520-
str += currentCharacter(state)
1526+
const cNext = nextCharacter(state)
1527+
if (cNext !== "'" && cNext !== '"') {
1528+
str += currentCharacter(state)
1529+
}
15211530
next(state)
15221531
}
15231532

@@ -1531,7 +1540,7 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({
15311540
}
15321541
getToken(state)
15331542

1534-
return JSON.parse('"' + str + '"') // unescape escaped characters
1543+
return JSON.parse('"' + str.replace(/"/g, '\\"') + '"') // unescape escaped characters
15351544
}
15361545

15371546
/**

src/function/algebra/derivative.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,8 @@ export const createDerivative = /* #__PURE__ */ factory(name, dependencies, ({
765765
}
766766

767767
node.compile().evaluate()
768-
throw new Error('Expected TypeError, but none found')
768+
769+
throw new Error('Function "' + node.name + '" is not supported by derivative, or a wrong number of arguments is passed')
769770
}
770771

771772
/**

src/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export const version = '11.11.1'
1+
export const version = '11.11.2'
22
// Note: This file is automatically generated when building math.js.
33
// Changes made in this file will be overwritten.

test/unit-tests/expression/parse.test.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,19 @@ describe('parse', function () {
364364
assert.deepStrictEqual(parseAndEval(' "hi" '), 'hi')
365365
})
366366

367+
it('should parse a string containing quotes', function () {
368+
// quote
369+
assert.deepStrictEqual(parseAndEval('"with\'quote"'), "with'quote")
370+
371+
// escaped quote -> remove escape character
372+
assert.deepStrictEqual(parseAndEval('"with\\"quote"'), 'with"quote')
373+
assert.deepStrictEqual(parseAndEval('"with\\\'quote"'), "with'quote")
374+
375+
// escaped escape character -> remove two escape characters
376+
assert.deepStrictEqual(parseAndEval('"with\\\\\\"quote"'), 'with\\"quote')
377+
assert.deepStrictEqual(parseAndEval('"with\\\\\'quote"'), "with\\'quote")
378+
})
379+
367380
it('should parse a with escaped characters', function () {
368381
assert.deepStrictEqual(parseAndEval('"line end\\nnext"'), 'line end\nnext')
369382
assert.deepStrictEqual(parseAndEval('"line end\\n"'), 'line end\n')
@@ -420,7 +433,20 @@ describe('parse', function () {
420433
assert.deepStrictEqual(parseAndEval(' \'hi\' '), 'hi')
421434
})
422435

423-
it('should parse a with escaped characters', function () {
436+
it('should parse a string containing quotes', function () {
437+
// quote
438+
assert.deepStrictEqual(parseAndEval("'with\"quote'"), 'with"quote')
439+
440+
// escaped quote -> remove escape character
441+
assert.deepStrictEqual(parseAndEval("'with\\'quote'"), "with'quote")
442+
assert.deepStrictEqual(parseAndEval("'with\\\"quote'"), 'with"quote')
443+
444+
// escaped escape character -> remove two escape characters
445+
assert.deepStrictEqual(parseAndEval("'with\\\\\\'quote'"), "with\\'quote")
446+
assert.deepStrictEqual(parseAndEval("'with\\\\\"quote'"), 'with\\"quote')
447+
})
448+
449+
it('should parse a string with escaped characters', function () {
424450
assert.deepStrictEqual(parseAndEval('\'line end\\nnext\''), 'line end\nnext')
425451
assert.deepStrictEqual(parseAndEval('\'line end\\n\''), 'line end\n')
426452
assert.deepStrictEqual(parseAndEval('\'tab\\tnext\''), 'tab\tnext')
@@ -772,6 +798,12 @@ describe('parse', function () {
772798
assert.deepStrictEqual(parseAndEval('obj.foo[1].bar', { obj: { foo: [{ bar: 4 }] } }), 4)
773799
})
774800

801+
it('should get a property with the name of an operator like "to" or "in"', function () {
802+
assert.deepStrictEqual(parseAndEval('obj.mod', { obj: { mod: 42 } }), 42)
803+
assert.deepStrictEqual(parseAndEval('obj.in', { obj: { in: 42 } }), 42)
804+
assert.deepStrictEqual(parseAndEval('obj.to', { obj: { to: 42 } }), 42)
805+
})
806+
775807
it('should set an object property', function () {
776808
const scope = { obj: { a: 3 } }
777809
const res = parseAndEval('obj["b"] = 2', scope)

test/unit-tests/function/algebra/derivative.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,12 @@ describe('derivative', function () {
238238
})
239239

240240
it('should throw error if expressions contain unsupported operators or functions', function () {
241-
assert.throws(function () { derivative('x << 2', 'x') }, /Error: Operator "<<" is not supported by derivative/)
242-
assert.throws(function () { derivative('subset(x)', 'x') }, /Error: Function "subset" is not supported by derivative/)
241+
assert.throws(function () { derivative('x << 2', 'x') }, /Error: Operator "<<" is not supported by derivative, or a wrong number of arguments is passed/)
242+
assert.throws(function () { derivative('subset(x)', 'x') }, /Error: Function "subset" is not supported by derivative, or a wrong number of arguments is passed/)
243+
assert.throws(function () { derivative('max(x)', 'x') }, /Error: Function "max" is not supported by derivative, or a wrong number of arguments is passed/)
244+
assert.throws(function () { derivative('max(x, y)', 'x') }, /Error: Function "max" is not supported by derivative, or a wrong number of arguments is passed/)
245+
assert.throws(function () { derivative('max(x, 1)', 'x') }, /Error: Function "max" is not supported by derivative, or a wrong number of arguments is passed/)
246+
assert.throws(function () { derivative('add(2,3,x)', 'x') }, /Error: Function "add" is not supported by derivative, or a wrong number of arguments is passed/)
243247
})
244248

245249
it('should have controlled behavior on arguments errors', function () {

0 commit comments

Comments
 (0)