Skip to content

Commit d116c36

Browse files
committed
Disallow temporal types in query params in HTTP driver
There currently exists no way for the REST endpoint to accept spatial and temporal types as query parameters. This commit makes driver fail fast so that given spatial or temporal objects are not misinterpreted as maps.
1 parent d4f3636 commit d116c36

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/v1/internal/http/http-response-converter.js

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {isInt} from '../../integer';
2121
import {Node, Path, PathSegment, Relationship} from '../../graph-types';
2222
import {Neo4jError, PROTOCOL_ERROR} from '../../error';
2323
import {isPoint, Point} from '../../spatial-types';
24+
import {isDate, isDateTime, isDuration, isLocalDateTime, isLocalTime, isTime} from '../../temporal-types';
2425

2526
const CREDENTIALS_EXPIRED_CODE = 'Neo.ClientError.Security.CredentialsExpired';
2627

@@ -145,6 +146,18 @@ function encodeQueryParameter(value) {
145146
throw new Neo4jError('It is not allowed to pass paths in query parameters', PROTOCOL_ERROR);
146147
} else if (isPoint(value)) {
147148
throw newUnsupportedParameterError('points');
149+
} else if (isDate(value)) {
150+
throw newUnsupportedParameterError('dates');
151+
} else if (isDateTime(value)) {
152+
throw newUnsupportedParameterError('date-time');
153+
} else if (isDuration(value)) {
154+
throw newUnsupportedParameterError('durations');
155+
} else if (isLocalDateTime(value)) {
156+
throw newUnsupportedParameterError('local date-time');
157+
} else if (isLocalTime(value)) {
158+
throw newUnsupportedParameterError('local time');
159+
} else if (isTime(value)) {
160+
throw newUnsupportedParameterError('time');
148161
} else if (isInt(value)) {
149162
return value.toNumber();
150163
} else if (Array.isArray(value)) {

test/internal/http/http-driver.test.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,40 @@ describe('http driver', () => {
287287
testUnsupportedQueryParameterWithHttpDriver(new neo4j.types.Path(node1, node2, []), done);
288288
});
289289

290+
it('should fail to pass point as a query parameter', done => {
291+
testUnsupportedQueryParameterWithHttpDriver(new neo4j.types.Point(neo4j.int(42), 1, 2, 3), done);
292+
});
293+
294+
it('should fail to pass date as a query parameter', done => {
295+
testUnsupportedQueryParameterWithHttpDriver(new neo4j.types.Date(2000, 10, 12), done);
296+
});
297+
298+
it('should fail to pass date-time as a query parameter', done => {
299+
testUnsupportedQueryParameterWithHttpDriver(new neo4j.types.DateTime(2000, 10, 12, 12, 12, 0, 0, 0, null), done);
300+
});
301+
302+
it('should fail to pass duration as a query parameter', done => {
303+
testUnsupportedQueryParameterWithHttpDriver(new neo4j.types.Duration(1, 1, 1, 1), done);
304+
});
305+
306+
it('should fail to pass local date-time as a query parameter', done => {
307+
testUnsupportedQueryParameterWithHttpDriver(new neo4j.types.LocalDateTime(2000, 10, 12, 10, 10, 10), done);
308+
});
309+
310+
it('should fail to pass local time as a query parameter', done => {
311+
testUnsupportedQueryParameterWithHttpDriver(new neo4j.types.LocalTime(12, 12, 12, 0), done);
312+
});
313+
314+
it('should fail to pass time as a query parameter', done => {
315+
testUnsupportedQueryParameterWithHttpDriver(new neo4j.types.Time(12, 12, 12, 0, 0), done);
316+
});
317+
290318
it('should receive points', done => {
291319
testReceivingOfResults([
292320
'RETURN point({x: 42.341, y: 125.0})',
293321
'RETURN point({x: 13.2, y: 22.2, z: 33.3})',
294322
'RETURN point({x: 92.3, y: 71.2, z: 2.12345, crs: "wgs-84-3d"})',
295-
'RETURN point({longitude: 56.7, latitude: 12.78})',
323+
'RETURN point({longitude: 56.7, latitude: 12.78})'
296324
], done);
297325
});
298326

0 commit comments

Comments
 (0)