Skip to content

Commit

Permalink
Fixes built-in function case sensitivity (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
anderson4j authored Feb 17, 2025
1 parent 816eb1b commit 6d00433
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-panthers-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@neo4j-cypher/language-support': patch
---

Bugfix for case-insensitivity of built-in functions
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,14 @@ function functionExists(
const functionExistsWithExactName = Boolean(
functionsSchema[functionCandidate.name],
);
const lowercaseFunctionName = functionCandidate.name.toLowerCase();
const caseInsensitiveFunctionInDatabase =
functionsSchema[lowercaseFunctionName];

// Built-in functions are case-insensitive in the database
return (
functionExistsWithExactName ||
(caseInsensitiveFunctionInDatabase &&
caseInsensitiveFunctionInDatabase.isBuiltIn)
const lowerCaseFunctionName = functionCandidate.name.toLowerCase();
const caseInsensitiveBuiltInFunctionExists = Boolean(
Object.values(functionsSchema).find(
(fn) => fn.isBuiltIn && fn.name.toLowerCase() === lowerCaseFunctionName,
),
);
// Built-in functions are case-insensitive in the database
return caseInsensitiveBuiltInFunctionExists || functionExistsWithExactName;
}

function generateFunctionUsedAsProcedureError(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { testData } from '../testData';
import { getDiagnosticsForQuery } from './helpers';

describe('Syntactic validation spec', () => {
Expand Down Expand Up @@ -744,6 +745,68 @@ describe('Syntactic validation spec', () => {
]);
});

test('Syntax validation does not error on case-insensitive use of built-in functions', () => {
const query = `RETURN randomUuId()`;

expect(
getDiagnosticsForQuery({
query,
dbSchema: {
functions: {
'CYPHER 5': {
randomUUID: {
...testData.emptyFunction,
name: 'randomUUID',
isBuiltIn: true,
},
},
},
},
}),
).toEqual([]);
});

test('Syntax validation returns error on case-insensitive use of non-built-in functions', () => {
const query = `RETURN apoc.madeup()`;

expect(
getDiagnosticsForQuery({
query,
dbSchema: {
functions: {
'CYPHER 5': {
'apoc.madeUp': {
...testData.emptyFunction,
name: 'apoc.madeUp',
isBuiltIn: false,
},
},
},
},
}),
).toEqual([
{
message:
"Function apoc.madeup is not present in the database. Make sure you didn't misspell it or that it is available when you run this statement in your application",
offsets: {
end: 18,
start: 7,
},
range: {
end: {
character: 18,
line: 0,
},
start: {
character: 7,
line: 0,
},
},
severity: 1,
},
]);
});

// TODO FIX ME
// Problem here is we were getting a better error before
test.fails('Syntax validation errors on an expected procedure name', () => {
Expand Down

0 comments on commit 6d00433

Please sign in to comment.