Skip to content

Fixes backticking of params #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 8, 2025
Merged

Fixes backticking of params #457

merged 8 commits into from
Apr 8, 2025

Conversation

anderson4j
Copy link
Collaborator

@anderson4j anderson4j commented Apr 3, 2025

Before we used the same backticking condition as the one for labels/reltypes/propertyKeys, which cant start with a number. Params can though, so we need a different condition.
Ex.

param "100param": RETURN $ ->
before: RETURN $`100param`
now: RETURN $100param

Copy link

changeset-bot bot commented Apr 3, 2025

🦋 Changeset detected

Latest commit: ece928e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@neo4j-cypher/language-support Patch
@neo4j-cypher/language-server Patch
@neo4j-cypher/react-codemirror-playground Patch
@neo4j-cypher/react-codemirror Patch
@neo4j-cypher/schema-poller Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@anderson4j anderson4j requested a review from ncordon April 4, 2025 09:21
@ncordon ncordon self-assigned this Apr 4, 2025
Comment on lines -45 to +44
if (e == null || e == '') {
return undefined;
} else if (/[^\p{L}\p{N}_]/u.test(e) || /[^\p{L}_]/u.test(e[0])) {
return `\`${e}\``;
} else {
return undefined;
}
}
type BacktickVariant = 'label' | 'propertyKey' | 'relType' | 'dbName' | 'param';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the need for having these many types. The only one that is different is param, so having 'param' | 'nonParam' would be more concise

Copy link
Collaborator Author

@anderson4j anderson4j Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dbName also has a special rule (periods are allowed without backticks if it's not the first or last symbol), and I figured for readability it's nice to see what type of elements we use which regex for

I did notice however that the old method was not checking for a period in the end of the dbname, so will adjust that

Copy link
Collaborator

@ncordon ncordon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a changeset

Comment on lines 61 to 63
(/[^\p{L}\p{N}_.]/u.test(e) ||
/[^\p{L}_]/u.test(e[0]) ||
/[^\p{L}\p{N}_]/u.test(e[e.length - 1]))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _ is not valid in a database name.

The nicer Typescript way to get the last element is e.at(-1)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are going to change this you should include tests for some db names:

some.database
database-
database.
100database

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I noticed the db-name thing while testing the last letter. Since this means that dbs cant have a _ in the string, e will never contain _, so this check doesnt affect valid dbnames. And since it still works for both direct names and aliases (and I think dbName is a nice shared variant name) I figure we can avoid an extra case by keeping it as is

Copy link
Collaborator Author

@anderson4j anderson4j Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e2e was failing so I think maybe some small detail was broken at the same time, but ill adjust to the nicer "-1"-way of indexing when i get to the bottom of the e2e test (edit: it seems like it was just flaky)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didnt see your second comment on my last message(s), but yeah we dont have any tests for certain odd but possible endings like - and ., so I will add these

@anderson4j anderson4j merged commit 88e4930 into main Apr 8, 2025
3 checks passed
@anderson4j anderson4j deleted the backtickParamFix branch April 8, 2025 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants