fix: reject negative manual dataset slices
Prevent negative Train Split Start/End values in the dataset advanced UI and sanitize payload mapping so negative slice values are never sent to the backend. Made-with: Cursor
This commit is contained in:
parent
226f251589
commit
5dcbf86d09
2 changed files with 16 additions and 3 deletions
|
|
@ -89,6 +89,13 @@ function formatUpdatedDate(timestamp: number | null): string {
|
|||
return new Date(timestamp * 1000).toLocaleDateString();
|
||||
}
|
||||
|
||||
function normalizeSliceInput(value: string): string | null {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) return null;
|
||||
if (!/^\d+$/.test(trimmed)) return null;
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
export function DatasetSection() {
|
||||
const {
|
||||
dataset,
|
||||
|
|
@ -783,11 +790,14 @@ export function DatasetSection() {
|
|||
</Tooltip>
|
||||
</span>
|
||||
<Input
|
||||
type="number"
|
||||
inputMode="numeric"
|
||||
min={0}
|
||||
step={1}
|
||||
placeholder="0"
|
||||
value={datasetSliceStart ?? ""}
|
||||
onChange={(e) =>
|
||||
setDatasetSliceStart(e.target.value || null)
|
||||
setDatasetSliceStart(normalizeSliceInput(e.target.value))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
|
@ -815,11 +825,14 @@ export function DatasetSection() {
|
|||
</Tooltip>
|
||||
</span>
|
||||
<Input
|
||||
type="number"
|
||||
inputMode="numeric"
|
||||
min={0}
|
||||
step={1}
|
||||
placeholder="End"
|
||||
value={datasetSliceEnd ?? ""}
|
||||
onChange={(e) =>
|
||||
setDatasetSliceEnd(e.target.value || null)
|
||||
setDatasetSliceEnd(normalizeSliceInput(e.target.value))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ function parseSliceValue(value: string | null): number | null {
|
|||
const trimmed = value.trim();
|
||||
if (!trimmed) return null;
|
||||
const num = Number(trimmed);
|
||||
if (!Number.isFinite(num) || !Number.isInteger(num)) return null;
|
||||
if (!Number.isFinite(num) || !Number.isInteger(num) || num < 0) return null;
|
||||
return num;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue