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

Zola 0.19.0 doesn't accept all valid YAML dates #2538

Closed
kytta opened this issue Jun 22, 2024 · 3 comments
Closed

Zola 0.19.0 doesn't accept all valid YAML dates #2538

kytta opened this issue Jun 22, 2024 · 3 comments
Labels
done in pr Already done in a PR

Comments

@kytta
Copy link
Contributor

kytta commented Jun 22, 2024

Bug Report

With 0.19.0, Zola can now understand more date formats. However, I believe there is a bug in the implementation which makes the millisecond separator (but not the milliseconds) required

Environment

Zola version: 0.19.0

Expected Behavior

2024-06-22 18:42:00 +02:00 should be a correct datetime

Current Behavior

Error: Failed to build the site
Error: Error when parsing front matter of section `path/to/file.md`
Error: Reason: YAML deserialize error: Error("Unable to parse datetime", line: 2, column: 1)

If I add a single dot after the seconds (2024-06-22 18:42:00. +02:00), the issue goes away.

Step to reproduce

  1. Create a Markdown file with a date like 2024-06-22 18:42:00 +02:00
  2. Try to zola build or zola serve
  3. Observe the error

Possible solution

I believe there is an error in the regex:

https://github.com/getzola/zola/blob/v0.19.0/components/utils/src/de.rs#L12

As you can see, the millisecond (aka fraction) part of the string is optional, but the period is not. This contradicts the YAML Working Draft on Timestamp which was mentioned in the original issue.

-    let re = Regex::new(r#"^"?([0-9]{4})-([0-9][0-9]?)-([0-9][0-9]?)([Tt]|[ \t]+)([0-9][0-9]?):([0-9]{2}):([0-9]{2})\.([0-9]*)?Z?([ \t]([-+][0-9][0-9]?)(:([0-9][0-9]?))?Z?|([-+][0-9]{2})?:([0-9]{2})?)?|([0-9]{4})-([0-9]{2})-([0-9]{2})"?$"#).unwrap();
+    let re = Regex::new(r#"^"?([0-9]{4})-([0-9][0-9]?)-([0-9][0-9]?)([Tt]|[ \t]+)([0-9][0-9]?):([0-9]{2}):([0-9]{2})(?:\.([0-9]*))?Z?([ \t]([-+][0-9][0-9]?)(:([0-9][0-9]?))?Z?|([-+][0-9]{2})?:([0-9]{2})?)?|([0-9]{4})-([0-9]{2})-([0-9]{2})"?$"#).unwrap();

Additional info

Same error also happens if I omit the seconds altogether (2024-06-22 18:42 +02:00). I may be opinionated, but I think requiring those should be optional, too.

Relates to #2071, #2208

@Keats
Copy link
Collaborator

Keats commented Jun 23, 2024

Can you submit the change as a PR with some additional tests?

@kytta
Copy link
Contributor Author

kytta commented Jun 25, 2024

@Keats will do :) would you also be interested in using named regex groups instead of indexed ones? I find it more readable and more flexible

@Keats
Copy link
Collaborator

Keats commented Jun 25, 2024

Sure go for it

@kytta kytta mentioned this issue Jun 25, 2024
3 tasks
Keats pushed a commit that referenced this issue Jun 27, 2024
* Refine YAML date regex

This commit does a few changes:

- Introduce a new regex
  - it is a bit off-spec (it allows one-digit months and days in date-only mode)
  - uses named groups
  - avoids group duplication
- parses offset once

Fixes #2538

* Fix nanosecond parsing

* Rename variables for brewity

* Add tests
@Keats Keats added the done in pr Already done in a PR label Jul 1, 2024
reujab pushed a commit to reujab/zola that referenced this issue Aug 14, 2024
* Refine YAML date regex

This commit does a few changes:

- Introduce a new regex
  - it is a bit off-spec (it allows one-digit months and days in date-only mode)
  - uses named groups
  - avoids group duplication
- parses offset once

Fixes getzola#2538

* Fix nanosecond parsing

* Rename variables for brewity

* Add tests
@Keats Keats closed this as completed in 56122de Aug 15, 2024
berdandy pushed a commit to berdandy/azola that referenced this issue Sep 17, 2024
* Refine YAML date regex

This commit does a few changes:

- Introduce a new regex
  - it is a bit off-spec (it allows one-digit months and days in date-only mode)
  - uses named groups
  - avoids group duplication
- parses offset once

Fixes getzola#2538

* Fix nanosecond parsing

* Rename variables for brewity

* Add tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
done in pr Already done in a PR
Projects
None yet
Development

No branches or pull requests

2 participants