Skip to content

Commit 6f555e5

Browse files
fix(web): only true deletions bypass the price cell check
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 8159356 commit 6f555e5

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

‎apps/web/src/components/usage/usagePriceForm.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ describe("model price entry", () => {
7979
expect(isUsagePriceEdit("", next)).toBe(false);
8080
});
8181

82-
it("never blocks deleting part of a price, but blocks replacing it with letters", () => {
82+
it("never blocks deleting part of a price, but blocks replacing it with a non-number", () => {
8383
expect(isUsagePriceEdit("1e-7", "e-7")).toBe(true);
8484
expect(isUsagePriceEdit("1e-7", "1-7")).toBe(true);
8585
expect(isUsagePriceEdit("1e-7", "a7")).toBe(false);
8686
expect(isUsagePriceEdit("2.5", "x")).toBe(false);
87+
expect(isUsagePriceEdit("123456", "1.2.3")).toBe(false);
8788
});
8889
});

‎apps/web/src/components/usage/usagePriceForm.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ export function usagePriceForm(model = "", price?: UsageModelPriceOverride): Usa
2525
/**
2626
* Whether a price cell may change from `previous` to `next` while typing:
2727
* digits with an optional decimal point, plus the exponent form saved rates can
28-
* stringify to. Deleting from a number is always allowed so a mid-value delete
29-
* such as `1e-7` to `e-7` is not stuck; saving still validates the result.
28+
* stringify to. Deleting a run of characters is always allowed so a mid-value
29+
* delete such as `1e-7` to `e-7` is not stuck; saving still validates the result.
3030
*/
3131
export function isUsagePriceEdit(previous: string, next: string): boolean {
32-
return (
33-
/^\s*(?:\d*\.?\d*|(?:\d+\.?\d*|\.\d+)e[+-]?\d*)\s*$/i.test(next) ||
34-
(next.length < previous.length && /^[\d.e+\-\s]*$/i.test(next))
35-
);
32+
if (/^\s*(?:\d*\.?\d*|(?:\d+\.?\d*|\.\d+)e[+-]?\d*)\s*$/i.test(next)) return true;
33+
if (next.length >= previous.length) return false;
34+
let start = 0;
35+
while (start < next.length && next[start] === previous[start]) start++;
36+
return next.slice(start) === previous.slice(previous.length - (next.length - start));
3637
}
3738

3839
/** Blank cache prices use the input rate; explicit zero means free. */

0 commit comments

Comments
 (0)