Skip to content

Commit edafb7d

Browse files
committed
check if statement text is empty on Session.run and Transaction.run
1 parent 548cbec commit edafb7d

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/v1/session.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Session {
5353

5454
/**
5555
* Run Cypher statement
56-
* Could be called with a statement object i.e.: {statement: "MATCH ...", parameters: {param: 1}}
56+
* Could be called with a statement object i.e.: {text: "MATCH ...", parameters: {param: 1}}
5757
* or with the statement and parameters as separate arguments.
5858
* @param {mixed} statement - Cypher statement to execute
5959
* @param {Object} parameters - Map with parameters to use in statement
@@ -65,6 +65,9 @@ class Session {
6565
statement = statement.text;
6666
}
6767
assertString(statement, 'Cypher statement');
68+
if (statement.length == 0) {
69+
throw new TypeError('Cypher statement is expected to be a non-empty string.');
70+
}
6871

6972
return this._run(statement, parameters, (connection, streamObserver) =>
7073
connection.run(statement, parameters, streamObserver)

src/v1/transaction.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Transaction {
5353

5454
/**
5555
* Run Cypher statement
56-
* Could be called with a statement object i.e.: <code>{statement: "MATCH ...", parameters: {param: 1}}</code>
56+
* Could be called with a statement object i.e.: <code>{text: "MATCH ...", parameters: {param: 1}}</code>
5757
* or with the statement and parameters as separate arguments.
5858
* @param {mixed} statement - Cypher statement to execute
5959
* @param {Object} parameters - Map with parameters to use in statement
@@ -65,6 +65,9 @@ class Transaction {
6565
statement = statement.text;
6666
}
6767
assertString(statement, "Cypher statement");
68+
if (statement.length == 0) {
69+
throw new TypeError('Cypher statement is expected to be a non-empty string.');
70+
}
6871

6972
return this._state.run(this._connectionHolder, new _TransactionStreamObserver(this), statement, parameters);
7073
}

test/v1/session.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ describe('session', () => {
427427
expect(() => session.run({})).toThrowError(TypeError);
428428
expect(() => session.run(42)).toThrowError(TypeError);
429429
expect(() => session.run([])).toThrowError(TypeError);
430+
expect(() => session.run('')).toThrowError(TypeError);
430431
expect(() => session.run(['CREATE ()'])).toThrowError(TypeError);
431432

432433
expect(() => session.run({statement: 'CREATE ()'})).toThrowError(TypeError);

0 commit comments

Comments
 (0)