Skip to content

feat(autocomplete): add type generator from the php yaml definitions #521

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

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

nirinchev
Copy link
Collaborator

Warning

This is very much WIP and likely to change significantly

Description

TBD

Open Questions

TBD

Checklist

@lerouxb lerouxb mentioned this pull request May 2, 2025
3 tasks
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fwiw my gut feeling would still be that the generated files are not something we need to check into the repo.

If you do want to keep them, I'd suggest doing something like https://github.com/mongodb/specifications/blob/master/.gitattributes where we inform GH that the files are generated so that we don't end up reviewing the diffs manually by default


return new Date(value);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, this looks a lot like the type of logic we have in https://github.com/mongodb-js/devtools-shared/tree/main/packages/ejson-shell-parser 🙂


class NumberLongProcessor extends RegexCustomTypeProcessor {
constructor() {
super('\\bNumberLong\\(\\s*"?([\\d\.]*)"?\\s*\\)');

Check failure

Code scanning / CodeQL

Useless regular-expression character escape High

The escape sequence '.' is equivalent to just '.', so the sequence may still represent a meta-character when it is used in a
regular expression
.

Copilot Autofix

AI 2 days ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

operatorFilter?: string,
): Promise<void> {
const categoryRegex = categoryFilter
? new RegExp(categoryFilter)

Check failure

Code scanning / CodeQL

Regular expression injection High

This regular expression is constructed from a
command-line argument
.
? new RegExp(categoryFilter)
: undefined;
const operatorRegex = operatorFilter
? new RegExp(operatorFilter)

Check failure

Code scanning / CodeQL

Regular expression injection High

This regular expression is constructed from a
command-line argument
.

Copilot Autofix

AI 2 days ago

To fix the issue, we need to sanitize the operatorFilter input before using it to construct a regular expression. The best way to achieve this is by using a library like lodash and its _.escapeRegExp function, which escapes special characters in a string to make it safe for use in a regular expression. This ensures that user input cannot introduce malicious patterns into the regular expression.

The changes will be made in the generate method of GeneratorBase in packages/mql-typescript/src/generator.ts. Additionally, we will add the required lodash import to the file.


Suggested changeset 2
packages/mql-typescript/src/generator.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/mql-typescript/src/generator.ts b/packages/mql-typescript/src/generator.ts
--- a/packages/mql-typescript/src/generator.ts
+++ b/packages/mql-typescript/src/generator.ts
@@ -4,2 +4,3 @@
 import * as fs from 'fs/promises';
+import _ from 'lodash';
 import * as yaml from 'js-yaml';
@@ -282,6 +283,6 @@
     const categoryRegex = categoryFilter
-      ? new RegExp(categoryFilter)
+      ? new RegExp(_.escapeRegExp(categoryFilter))
       : undefined;
     const operatorRegex = operatorFilter
-      ? new RegExp(operatorFilter)
+      ? new RegExp(_.escapeRegExp(operatorFilter))
       : undefined;
EOF
@@ -4,2 +4,3 @@
import * as fs from 'fs/promises';
import _ from 'lodash';
import * as yaml from 'js-yaml';
@@ -282,6 +283,6 @@
const categoryRegex = categoryFilter
? new RegExp(categoryFilter)
? new RegExp(_.escapeRegExp(categoryFilter))
: undefined;
const operatorRegex = operatorFilter
? new RegExp(operatorFilter)
? new RegExp(_.escapeRegExp(operatorFilter))
: undefined;
packages/mql-typescript/package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/mql-typescript/package.json b/packages/mql-typescript/package.json
--- a/packages/mql-typescript/package.json
+++ b/packages/mql-typescript/package.json
@@ -80,3 +80,4 @@
     "yargs": "^17.7.2",
-    "zod": "^3.24.2"
+    "zod": "^3.24.2",
+    "lodash": "^4.17.21"
   }
EOF
@@ -80,3 +80,4 @@
"yargs": "^17.7.2",
"zod": "^3.24.2"
"zod": "^3.24.2",
"lodash": "^4.17.21"
}
This fix introduces these dependencies
Package Version Security advisories
lodash (npm) 4.17.21 None
Copilot is powered by AI and may make mistakes. Always verify output.
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.

3 participants