-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: main
Are you sure you want to change the base?
Conversation
… have a schema defined
There was a problem hiding this comment.
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); | ||
} | ||
} |
There was a problem hiding this comment.
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
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
command-line argument
? new RegExp(categoryFilter) | ||
: undefined; | ||
const operatorRegex = operatorFilter | ||
? new RegExp(operatorFilter) |
Check failure
Code scanning / CodeQL
Regular expression injection High
command-line argument
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R5 -
Copy modified line R284 -
Copy modified line R287
@@ -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; |
-
Copy modified lines R81-R82
@@ -80,3 +80,4 @@ | ||
"yargs": "^17.7.2", | ||
"zod": "^3.24.2" | ||
"zod": "^3.24.2", | ||
"lodash": "^4.17.21" | ||
} |
Package | Version | Security advisories |
lodash (npm) | 4.17.21 | None |
Warning
This is very much WIP and likely to change significantly
Description
TBD
Open Questions
TBD
Checklist