question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] string Slug incorrectly parsed as Date if in a specific format

See original GitHub issue

I have a controller that looks like so:

@Crud({
  model: {
    type: Product,
  },
  params: {
    id: {
      field: "id",
      type: "string",
      primary: true,
    },
  },

When GET ing product with id like so: /api/products/product-123123 The SQL query ends with:

WHERE `Brand`.`bt_brand_id` = ?) `distinctAlias` ORDER BY `Brand_bt_brand_id` ASC LIMIT 100 -- PARAMETERS: ["0122-12-31T21:39:06.000Z"]

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: https://github.com/nestjsx/crud/blob/3d3f60420072aec296207ecfa06a8f1cb0194f2e/packages/crud-request/src/request-query.parser.ts#L167

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
Bnayacommented, Jul 16, 2019

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]);
};

0reactions
Bnayacommented, Jul 21, 2019

I think its due to json.parse that is part of the pipeline This behavior is not documented and i dont see why regular string wont work

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does Date.parse give incorrect results? - Stack Overflow
This behaviour is specified in ECMA-262 so all browsers do it the same way. While there is some variance in the input string...
Read more >
Date and Time Conversions - APOC Extended Documentation
This function parses a date string in a specified format and converts it to a Neo4j-supported temporal type with date, time, and timezone....
Read more >
Date.parse() - JavaScript - MDN Web Docs
The Date.parse() method parses a string representation of a date, and returns the ... A library can help if many different formats are...
Read more >
Serializer fields - Django REST framework
input_formats - A list of strings representing the input formats which may be used to parse the date. If not specified, the DATE_INPUT_FORMATS ......
Read more >
Cannot query field frontmatter on type markdownremark
No more frontmatter types Tutorial Part Six Error: Cannot query field ... another problem is GraphQL template string doesn't allow string 22 квіт....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found