Repository: decaporg/decap-cms (JavaScript)

Issue:
Can't parse date in front matter
<!--
If you are reporting a new issue, make sure that we do not have any duplicates already open. You can ensure this by searching the issue list for this repository. If there is a duplicate, please add a comment to the existing issue instead.

Please include as much of the information requested below as possible. If you fail to provide the requested information within 7 days, we cannot debug your issue and will close it. We will, however, reopen it if you later provide the information.

If you have an issue that can be shown visually, please provide a screenshot or GIF of the problem as well.
-->

**Describe the bug**

NetlifyCMS breaks trying to parse dates of the format `YYYY-MM-DD` in the front-matter.

**To Reproduce**

Have a collections config like this:

```

collections:
  - name: "blog" # Used in routes, e.g., /admin/collections/blog
    label: "Blog" # Used in the UI
    folder: "content/blog" # The path to the folder where the documents are stored
    format: toml-frontmatter
    create: true # Allow users to create new documents in this collection
    fields: # The fields for each document, usually in front matter
      - {label: "Title", name: "title", widget: "string"}
      - {label: "Date", name: "date", widget: "date", format: "YYYY-MM-DD"}
      - {label: "Body", name: "body", widget: "markdown"}
```

Have a blog article with the following front matter:
```
+++
title = "An Example Blog"
date = 2018-12-14
+++

This is an example blog
```

You will see this in the console:

```
Object { message: "Expected \"T\" but \"\\n\" found.", line: 3, column: 18, stack: "" }
```

**Expected behavior**

The collection date is parsed correctly.




Discussion:
@cetra3  I think the issue here is the frontmatter. The right format should look like so:
```
+++
title = "An Example Blog"
date = "2018-12-14"
+++
```
May I ask, was the frontmatter generated via the CMS?
The frontmatter was not generated by netlify, it was an existing blog that wasn't read.

According to the [TOML spec](https://github.com/toml-lang/toml#local-date) dates do not require quotes:

>Local Date
>If you include only the date portion of an RFC 3339 formatted date-time, it will represent that entire day without any relation to an offset or timezone.
> `ld1 = 1979-05-27`
@cetra3  investigated this issue further and the error seems to be coming from `toml-j0.4` parser we are using to parse `toml` files. The parser only recognizes `datetime` format https://jakwings.github.io/toml-j0.4/. The simple workaround at the moment is to inclose your values in quotes.


Good point @barthc. @cetra3 if you're up for opening an issue in the toml parser repo, that would be the place for a fix to occur.
Actually, this isn't a bug so much as an improvement request: Netlify CMS currently supports TOML 0.4, which doesn't support this. The linked spec is for TOML 0.5, which doesn't yet have a stable release.
Ah, that makes sense.  The error message makes it look like it's coming from moment.js though.
Isn't https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.5.0.md a stable release from 2018?
It has a pre-release tag on the GH release page but so does every versions.
Looks like Netlify CMS is using [toml-j0.4](https://github.com/jakwings/toml-j0.4) as its parser, which does not support TOML 0.5, and has not seen active development for two years. Thus, resolving this likely means replacing the parser with another library.
Yep, it's about the library we're using, not the spec.



Patch:
diff --git a/packages/netlify-cms-core/package.json b/packages/netlify-cms-core/package.json
index 2121973652be..c23dd48256c7 100644
--- a/packages/netlify-cms-core/package.json
+++ b/packages/netlify-cms-core/package.json
@@ -59,7 +59,7 @@
     "redux-thunk": "^2.3.0",
     "sanitize-filename": "^1.6.1",
     "semaphore": "^1.0.5",
-    "toml-j0.4": "^1.1.1",
+    "@iarna/toml": "2.2.3",
     "tomlify-j0.4": "^3.0.0-alpha.0",
     "url": "^0.11.0",
     "what-input": "^5.1.4"
diff --git a/packages/netlify-cms-core/src/formats/toml.js b/packages/netlify-cms-core/src/formats/toml.js
index 7741bb4bc89c..9a228f1480b4 100644
--- a/packages/netlify-cms-core/src/formats/toml.js
+++ b/packages/netlify-cms-core/src/formats/toml.js
@@ -1,4 +1,4 @@
-import toml from 'toml-j0.4';
+import toml from '@iarna/toml';
 import tomlify from 'tomlify-j0.4';
 import moment from 'moment';
 import AssetProxy from 'ValueObjects/AssetProxy';
diff --git a/yarn.lock b/yarn.lock
index 83df053e432e..8c7c3c2acde4 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -981,6 +981,11 @@
     unique-filename "^1.1.1"
     which "^1.3.1"
 
+"@iarna/toml@2.2.3":
+  version "2.2.3"
+  resolved "https://registry.yarnpkg.com/@iarna/toml/-/toml-2.2.3.tgz#f060bf6eaafae4d56a7dac618980838b0696e2ab"
+  integrity sha512-FmuxfCuolpLl0AnQ2NHSzoUKWEJDFl63qXjzdoWBVyFCXzMGm1spBzk7LeHNoVCiWCF7mRVms9e6jEV9+MoPbg==
+
 "@jest/console@^24.7.1":
   version "24.7.1"
   resolved "https://registry.yarnpkg.com/@jest/console/-/console-24.7.1.tgz#32a9e42535a97aedfe037e725bd67e954b459545"
@@ -12188,11 +12193,6 @@ toidentifier@1.0.0:
   resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"
   integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==
 
-toml-j0.4@^1.1.1:
-  version "1.1.1"
-  resolved "https://registry.yarnpkg.com/toml-j0.4/-/toml-j0.4-1.1.1.tgz#eb0c70348609a0263bb1d6e4a3dd191dcca60866"
-  integrity sha512-lYK5otg0+cto8YmsWcPEfeiTiC/VU6P6HA6ooaYI9K/KYT24Jg0BrYtRZK1K3cwakSMyh6nttfJL9RmQH0gyCg==
-
 tomlify-j0.4@^3.0.0-alpha.0:
   version "3.0.0"
   resolved "https://registry.yarnpkg.com/tomlify-j0.4/-/tomlify-j0.4-3.0.0.tgz#99414d45268c3a3b8bf38be82145b7bba34b7473"


Test patch:
diff --git a/packages/netlify-cms-core/src/formats/__tests__/frontmatter.spec.js b/packages/netlify-cms-core/src/formats/__tests__/frontmatter.spec.js
index 1c04964bff2a..246f44bbd690 100644
--- a/packages/netlify-cms-core/src/formats/__tests__/frontmatter.spec.js
+++ b/packages/netlify-cms-core/src/formats/__tests__/frontmatter.spec.js
@@ -83,6 +83,16 @@ describe('Frontmatter', () => {
     });
   });
 
+  it('should parse TOML with 0.5 style dates', () => {
+    expect(
+      FrontmatterInfer.fromFile('+++\ntitle = "TOML"\ndate = 2018-12-24\n+++\nContent'),
+    ).toEqual({
+      title: 'TOML',
+      date: new Date('2018-12-24T00:00:00.000Z'),
+      body: 'Content',
+    });
+  });
+
   it('should parse TOML with +++ delimiters when it is explicitly set as the format without a custom delimiter', () => {
     expect(
       frontmatterTOML('~~~').fromFile(