Skip to content

Commit

Permalink
fix(stega): resolve issue where strings that ends in numbers are mist…
Browse files Browse the repository at this point in the history
…aken for datetimes
  • Loading branch information
stipsan committed Jan 26, 2024
1 parent 1d2ba4e commit 6b64cc4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/stega/filterDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const denylist = new Set([
])

function isValidDate(dateString: string) {
return Number.isNaN(Number(dateString)) ? Boolean(Date.parse(dateString)) : false
return /^\d{4}-\d{2}-\d{2}/.test(dateString) ? Boolean(Date.parse(dateString)) : false
}

function isValidURL(url: string) {
Expand Down
28 changes: 15 additions & 13 deletions test/stega/__snapshots__/stegaEncodeSourceMap.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`GraphQL API > decode all 1`] = `
[
"https://test.sanity.studio/intent/edit/mode=presentation;id=9696c833-fe71-45b8-b29d-68e8cd78d3db;type=post;path=title",
"https://test.sanity.studio/intent/edit/mode=presentation;id=ab9e2f38-6ea5-4264-b923-51ae8901ab8e;type=post;path=title",
]
`;

Expand All @@ -14,17 +15,11 @@ exports[`GraphQL API > logger.log 1`] = `
"[@sanity/client/stega]: Encoding source map into result",
],
[
"[@sanity/client/stega]: Paths encoded: 1, skipped: 1",
"[@sanity/client/stega]: Paths encoded: 2, skipped: 0",
],
[
"[@sanity/client/stega]: Table of encoded paths",
],
[
"[@sanity/client/stega]: List of skipped paths",
[
"title",
],
],
]
`;

Expand All @@ -37,6 +32,11 @@ exports[`GraphQL API > logger.table 1`] = `
"path": "title",
"value": "Stay tuned for detai...",
},
{
"length": 28,
"path": "title",
"value": "Anticipation is buil...",
},
],
],
]
Expand Down Expand Up @@ -73,7 +73,7 @@ exports[`resolveEditUrl '/' > logger.log 1`] = `
"[@sanity/client/stega]: Encoding source map into result",
],
[
"[@sanity/client/stega]: Paths encoded: 18, skipped: 80",
"[@sanity/client/stega]: Paths encoded: 18, skipped: 81",
],
[
"[@sanity/client/stega]: Table of encoded paths",
Expand All @@ -91,6 +91,7 @@ exports[`resolveEditUrl '/' > logger.log 1`] = `
"media[].asset._ref",
"media[].asset._type",
"_id",
"lastModified",
],
],
]
Expand Down Expand Up @@ -176,9 +177,9 @@ exports[`resolveEditUrl '/' > logger.table 1`] = `
"value": "Meet Ripple, a new s...",
},
{
"length": 13,
"length": 34,
"path": "title",
"value": "Ripple Sconce",
"value": "Ripple 1996-12-20T00...",
},
{
"length": 4,
Expand Down Expand Up @@ -226,7 +227,7 @@ exports[`resolveEditUrl 'https://test.sanity.studio' > logger.log 1`] = `
"[@sanity/client/stega]: Encoding source map into result",
],
[
"[@sanity/client/stega]: Paths encoded: 18, skipped: 80",
"[@sanity/client/stega]: Paths encoded: 18, skipped: 81",
],
[
"[@sanity/client/stega]: Table of encoded paths",
Expand All @@ -244,6 +245,7 @@ exports[`resolveEditUrl 'https://test.sanity.studio' > logger.log 1`] = `
"media[].asset._ref",
"media[].asset._type",
"_id",
"lastModified",
],
],
]
Expand Down Expand Up @@ -329,9 +331,9 @@ exports[`resolveEditUrl 'https://test.sanity.studio' > logger.table 1`] = `
"value": "Meet Ripple, a new s...",
},
{
"length": 13,
"length": 34,
"path": "title",
"value": "Ripple Sconce",
"value": "Ripple 1996-12-20T00...",
},
{
"length": 4,
Expand Down
12 changes: 11 additions & 1 deletion test/stega/stegaEncodeSourceMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,13 @@ const mock = {
},
},
_id: 'e1bf9f1f-efdb-4105-8c26-6b64f897e9c1',
title: 'Ripple Sconce',
title: 'Ripple 1996-12-20T00:39:57Z Sconce',
},
],
siteSettings: {
title: 'acme',
copyrightText: 'acme © 2023 — all rights reserved',
lastModified: '2024-01-01',
},
},
resultSourceMap: {
Expand Down Expand Up @@ -271,6 +272,7 @@ const mock = {
"$['media'][?(@._key=='3239041c90c8')]",
"$['media'][?(@._key=='c3c15f50cc9b')]",
"$['copyrightText']",
"$['lastModified']",
],
mappings: {
"$['products'][0]['_id']": {
Expand Down Expand Up @@ -489,6 +491,14 @@ const mock = {
},
type: 'value',
},
"$['siteSettings']['lastModified']": {
source: {
document: 5,
path: 10,
type: 'documentValue',
},
type: 'value',
},
},
},
ms: 40,
Expand Down

0 comments on commit 6b64cc4

Please sign in to comment.