-
-
Notifications
You must be signed in to change notification settings - Fork 546
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
[BUG] string Slug incorrectly parsed as Date if in a specific format #161
Comments
After additional debug, the issue is here: crud/packages/crud-request/src/request-query.parser.ts Lines 255 to 260 in 3d3f604
Even tho the type is configured as string, this.parseValue parses it as Date. |
My Workaround: // workaround for https://github.com/nestjsx/crud/issues/161
const m = require("@nestjsx/util/lib/checks.util.js");
const origIsDateString = m.isDateString;
m.isDateString = (v: any) => {
if (typeof v === "string") {
if (/^[a-z]+-[0-9]+$/i.test(v)) {
return false;
}
}
return origIsDateString.apply(m, [v]);
}; |
Same issue - I use the following filter "?filter=someParam||cont||CG-7" and "CG-7" is automatically resolved to date time |
More up to date workaround: // workaround for https://github.com/nestjsx/crud/issues/161
const m = require("@nestjsx/util/lib/checks.util.js");
const origIsDateString = m.isDateString;
// eslint-disable-next-line no-useless-escape
const datePattern = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)(Z|([+\-])(\d{2}):(\d{2}))$/;
m.isDateString = (v: any) => {
if (typeof v === "string") {
if (!datePattern.test(v)) {
return false;
}
}
return origIsDateString.apply(m, [v]);
}; |
Looks like parameter should be escaped so it works correctly (string is passed as-is w/o attempt to be converted to date time); The following works for me: |
I think its due to json.parse that is part of the pipeline |
I have a controller that looks like so:
When GET ing product with id like so:
/api/products/product-123123
The SQL query ends with:
When the ID format is not STRING-NUMBER, its all file.
I assume the lib has some heuristics, that are incorrect?
Maybe it's here:
crud/packages/crud-request/src/request-query.parser.ts
Line 167 in 3d3f604
The text was updated successfully, but these errors were encountered: