gothinkster / realworld

"The mother of all demo apps" — Exemplary fullstack Medium.com clone powered by React, Angular, Node, Django, and many more
https://www.realworld.how/
MIT License
80.42k stars 7.32k forks source link

[Bug]: Regex in Postman collection rejects valid ISO-8601 timestamps #832

Open abonander opened 2 years ago

abonander commented 2 years ago

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: https://github.com/gothinkster/realworld/blob/6e73f5ee714ae502f5f6ef4aa95bd10fec4ae59b/api/Conduit.postman_collection.json#L332

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 commented 2 years ago

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