Skip to content
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]: Regex in Postman collection rejects valid ISO-8601 timestamps #832

Open
abonander opened this issue Dec 14, 2021 · 1 comment
Open
Assignees
Labels

Comments

@abonander
Copy link

abonander commented Dec 14, 2021

Relevant scope

Other: describe below

Description

I'm working on a Rust implementation of the backend spec, and I'm using time 0.2 for timestamps such as the createdAt timestamps of Articles.

The RFC 3339 (subset of ISO 8601) formatter included with time 0.2 produces timestamps like this: 2021-12-14T03:09:36+00:00

This is a valid ISO 8601 timestamp and can be parsed using, e.g. Javascript's Date.parse() just fine, but it gets rejected by the regex used in the Postman collection here:

↳ Create Article
  POST http://localhost:8080/api/articles [200 OK, 450B, 15ms]
  ✓  Response contains "article" property
  ✓  Article has "title" property
  ✓  Article has "slug" property
  ✓  Article has "body" property
  ✓  Article has "createdAt" property
  7. Article's "createdAt" property is an ISO 8601 timestamp
  ✓  Article has "updatedAt" property
  8. Article's "updatedAt" property is an ISO 8601 timestamp
  ✓  Article has "description" property
  ✓  Article has "tagList" property
  ✓  Article's "tagList" property is an Array
  ✓  Article has "author" property
  ✓  Article has "favorited" property
  ✓  Article has "favoritesCount" property
  ✓  favoritesCount is an integer

I'm not sure the regex being used is entirely correct here:

" tests['Article\\'s \"createdAt\" property is an ISO 8601 timestamp'] = /^\\d{4,}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d.\\d+(?:[+-][0-2]\\d:[0-5]\\d|Z)$/.test(article.createdAt);",

Unescaped version:

^\d{4,}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d.\d+(?:[+-][0-2]\d:[0-5]\d|Z)$

It appears to require a decimal subsecond segment but matches on the decimal separator using an unescaped . which matches any single character instead of an escaped \. matching a literal dot. If I tweak the regex to fix this and make the subsecond fragment optional, my timestamp passes:

^\d{4,}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(\.\d+)?(?:[+-][0-2]\d:[0-5]\d|Z)$
@abonander
Copy link
Author

Didn't realize there was a PR opened for exactly this already: #490

@abonander abonander changed the title [Bug]: Postman collection has a bug in the regex for matching ISO-8601 dates [Bug]: Regex in Postman collection rejects valid ISO-8601 timestamps Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants