Repository navigation
Conversation
The page script took a payment's amount with /(US)?[$€£]\s?\d[\d,]*(\.\d{2})?/,
which stops at the first point of a number grouped with points and
leaves out the letters before the sign. "Total R$ 1.234,56" (Brazilian
reais, about 220 US dollars) was held as "$1.23", and "€ 1.299,00" as
"€1.29": the card and the pay sheet asked for those amounts, and
AgentRules.dollars counted $1.23 under the spending limit, so an agent
paid it without asking. The A$ and C$ check there never saw the A or C.
The script now keeps the letters before the sign and the number to its
last digit. AgentRules.dollars takes only "$" and "US$" as dollars and
reads the number through Calc.digits, so "$1.234,56" is 1,234.56.
[Critical impact] The change affects when an agent can pay without asking the person. Fix mixed-case currency prefixes before merging so non-US payments cannot skip approval. Findings
SummaryKeeps grouped digits and currency prefixes in payment amounts, then uses
Deferred scope: r0c0y explicitly deferred currency signs after the number as a separate change. Reviews (1) · Last reviewed commit: "Read the amount an agent pays whole and ..." · Reviewed by Greptile |
| // the total's line of its form or page, or the line under it. Whole, | ||
| // with the letters before its sign (US$, A$, R$) and its digits as | ||
| // written: "€ 1.299,00" was read only to its first point, €1.29. | ||
| const cash = /(\\b[A-Z]{1,3})?[$€£]\\s?\\d(?:[\\d.,]*\\d)?/; |
There was a problem hiding this comment.
For Total Mex$19.99, [A-Z]{1,3} cannot match the mixed-case prefix, so cash falls back to $19.99. dollars accepts that as US dollars, and Bench.decide can pay without asking under a $20 limit. Preserve mixed-case currency prefixes, or reject the amount rather than falling back to a bare dollar sign.
There was a problem hiding this comment.
Right, fixed in c71f8e2: the prefix is [A-Za-z]{1,3} now, so Total Mex$19.99 is held as Mex$19.99, and AgentRules.dollars gives nil for it, which asks. \b still keeps a longer word out of the prefix: Total$5 is $5, as before. Mex$19.99 is in the unit test, and the Chromium run of about() gives Mex$19.99 here ($19.99 on main).
[A-Z]{1,3} left Mex$19.99 as $19.99, counted as US dollars (review).
What changes
When an agent presses Pay, the amount on the card and the pay sheet is the page's, whole and in its currency:
R$1.234,56, not$1.23, and€1.299,00, not€1.29. Only US dollars count toward the spending limit, so a total in reais, Hong Kong dollars or pesos asks instead of being paid as dollars.Fixes #1146
Why it happened
Two readings, one after the other:
aboutinAgentPermit.swift) took the amount with/(US)?[$€£]\s?\d[\d,]*(\.\d{2})?/.[\d,]*stops at a point that groups thousands, so1.234,56became1.23, and only aUSbefore the sign was kept.AgentRules.dollarskept every digit and point of what it got, and checked forA$andC$, which the script had already cut to$.Now:
/(\b[A-Za-z]{1,3})?[$€£]\s?\d(?:[\d.,]*\d)?/.AgentRules.dollarscounts an amount only when its sign is$orUS$, and reads the number throughCalc.digits, the calculator's reading of grouped digits (Read 1,5 in the field's calculator as one and a half, not fifteen #1080):$1,234.56and$1.234,56are both 1,234.56. Anything it can't read gives nil, which asks.Proof
mainand pass here:swift test --filter "ReleaseGuardsTests|AgentHoldTests"(testOnlyUSDollarsCountTowardTheLimitAsWritten,testAnAmountIsHeldWholeWithItsCurrency)I can't build Yab here (no Xcode), so I ran both changed pieces on their own:
about(), taken fromAgentPermit.swiftonmainand on this branch, in Chromium (Playwright), onAgentHoldTests' page with the new form, then on a few checkouts:mainTotal R$ 1.234,56(the new test's form)$1.23R$1.234,56Order total $42.10(the existing test's form)$42.10$42.10Order total € 1.299,00€1.29€1.299,00Order total A$50.00$50.00A$50.00Order total HK$ 780.00$780.00HK$780.00Order total Mex$19.99$19.99Mex$19.99Order total $1,234.56$1,234.56$1,234.56Order total $42.10.$42.10$42.10ORDER TOTAL$42.10$42.10$42.10Pay US$42.10US$42.10US$42.10AgentRules.dollarsfrom both, compiled withCalculator.swift: the new unit test's lines fail onmainfor$1.234,56(1.23),R$1.234,56(1.23),HK$780.00(780),MX$1,000.00(1000) andMex$19.99(19.99), and all pass here.AgentHoldTestsitself runs in WebKit, which I couldn't run here; the page script is the same one I ran in Chromium.Checked on
AgentHoldTests, not run hereChecklist
swift testpasses (or the suites this touches: list them):ReleaseGuardsTests,AgentHoldTests; not run withswift testhere, see above./design-check --headis clean, or each exception says why with// design:NativeActions.swift(none)A total written with its sign after the number (
1.299,00 €, as in German and French) still has no amount, as before, and so asks. Reading those too would be a separate change.Written by an AI coding agent (Claude Code, Claude Opus 5.5) at my request.