Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/lib/components/filters/content.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import type { Column } from '$lib/helpers/types';
import type { Writable } from 'svelte/store';
import { TagList } from '.';
import { toLocalDateTimeISO } from '$lib/helpers/date';
import { Icon, Layout } from '@appwrite.io/pink-svelte';
import { IconPlus } from '@appwrite.io/pink-icons-svelte';
Expand Down Expand Up @@ -79,7 +80,7 @@
value = column?.array ? [] : null;
if (column?.type === 'datetime') {
const now = new Date();
value = now.toISOString().slice(0, 16);
value = toLocalDateTimeISO(now.toISOString()).slice(0, 16);
}
// Initialize spatial data with default values
if (column?.type === 'point') {
Expand Down Expand Up @@ -108,7 +109,11 @@
if (isDistanceOperator && distanceValue !== null && value !== null) {
addFilter(columnsArray, columnId, operatorKey, value, arrayValues, distanceValue);
} else {
addFilter(columnsArray, columnId, operatorKey, value, arrayValues);
const preparedValue =
column?.type === 'datetime' && typeof value === 'string' && value
? new Date(value).toISOString()
: value;
addFilter(columnsArray, columnId, operatorKey, preparedValue, arrayValues);
Comment on lines +112 to +116
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add error handling for datetime conversion.

The conversion from datetime-local string to UTC ISO lacks error handling. If value contains an invalid datetime string, new Date(value) returns an Invalid Date object, and calling toISOString() on it will throw a TypeError, potentially crashing the filter application.

Apply this diff to add error handling:

-            const preparedValue =
-                column?.type === 'datetime' && typeof value === 'string' && value
-                    ? new Date(value).toISOString()
-                    : value;
+            let preparedValue = value;
+            if (column?.type === 'datetime' && typeof value === 'string' && value) {
+                const date = new Date(value);
+                if (!isNaN(date.getTime())) {
+                    preparedValue = date.toISOString();
+                }
+            }
             addFilter(columnsArray, columnId, operatorKey, preparedValue, arrayValues);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const preparedValue =
column?.type === 'datetime' && typeof value === 'string' && value
? new Date(value).toISOString()
: value;
addFilter(columnsArray, columnId, operatorKey, preparedValue, arrayValues);
let preparedValue = value;
if (column?.type === 'datetime' && typeof value === 'string' && value) {
const date = new Date(value);
if (!isNaN(date.getTime())) {
preparedValue = date.toISOString();
}
}
addFilter(columnsArray, columnId, operatorKey, preparedValue, arrayValues);
🤖 Prompt for AI Agents
In src/lib/components/filters/content.svelte around lines 112–116, the
conversion new Date(value).toISOString() can throw for invalid datetime strings;
wrap the conversion in a try/catch (or construct the Date and check
isNaN(date.getTime())) and only call toISOString() when the Date is valid; on
invalid input, avoid throwing by either leaving preparedValue as the original
value, set preparedValue to null/undefined to skip the filter, and/or surface a
user-friendly validation error before calling addFilter so the filter
application doesn't crash.

}
columnId = null;
Expand Down
8 changes: 6 additions & 2 deletions src/lib/components/filters/filtersModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@
}
function addCondition() {
const newTag = generateTag(selectedColumn, operatorKey, value || arrayValues);
const preparedValue =
column?.type === 'datetime' && typeof value === 'string' && value
? new Date(value).toISOString()
: value;
Comment on lines +60 to +63
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add error handling for datetime conversion.

This conversion logic has the same issue as in content.svelte: if value contains an invalid datetime string, new Date(value).toISOString() will throw a TypeError.

Apply this diff to add error handling:

-        const preparedValue =
-            column?.type === 'datetime' && typeof value === 'string' && value
-                ? new Date(value).toISOString()
-                : value;
+        let preparedValue = value;
+        if (column?.type === 'datetime' && typeof value === 'string' && value) {
+            const date = new Date(value);
+            if (!isNaN(date.getTime())) {
+                preparedValue = date.toISOString();
+            }
+        }
         const newTag = generateTag(selectedColumn, operatorKey, preparedValue || arrayValues);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const preparedValue =
column?.type === 'datetime' && typeof value === 'string' && value
? new Date(value).toISOString()
: value;
let preparedValue = value;
if (column?.type === 'datetime' && typeof value === 'string' && value) {
const date = new Date(value);
if (!isNaN(date.getTime())) {
preparedValue = date.toISOString();
}
}
🤖 Prompt for AI Agents
In src/lib/components/filters/filtersModal.svelte around lines 60 to 63, the
datetime conversion uses new Date(value).toISOString() which can throw for
invalid strings; wrap the conversion in a try/catch (or validate the Date by
checking isNaN(date.getTime())) and only call toISOString() on a valid Date,
otherwise fall back to the original value (or null/empty as appropriate) and
optionally log or ignore the parse error so the component does not throw.

const newTag = generateTag(selectedColumn, operatorKey, preparedValue || arrayValues);
if (localTags.some((t) => t.tag === newTag.tag && t.value === newTag.value)) {
return;
} else {
Expand All @@ -66,7 +70,7 @@
{
id: selectedColumn,
operator: operatorKey,
value: value,
value: preparedValue,
arrayValues: arrayValues
}
];
Expand Down