{"success":true,"name":"a-parse-that-stops-halfway-is-not-a-success-12abc-quietly-be","description":"Converting text to a number, and garbage input still produces a value","category":"ai-brimind","path":"ai-brimind/a-parse-that-stops-halfway-is-not-a-success-12abc-quietly-be/SKILL.md","file":"SKILL.md","content":"---\nname: a-parse-that-stops-halfway-is-not-a-success-12abc-quietly-be\ndescription: \"Converting text to a number, and garbage input still produces a value\"\n---\n\n# A Parse That Stops Halfway Is Not a Success: '12abc' Quietly Becomes 12\n\n## When to use\nCode converts strings to numbers with functions that accept partial matches, and invalid input flows onward as a plausible-looking number.\n\n## Example request\nparseInt('12abc') → returns 12, no error; the garbage half vanished. '3.5.7' parsed → 3.5 accepted, the typo swallowed; partial read as success. quantity field '10x' → order created for 10; wrong data with a straight face. — each conversion graded itself pass by reading only the beginning.\n\n## Instructions\nAct as an exam grader who fails a half-answered paper instead of scoring only the attempted lines. Many parsing functions are lenient by design: they read from the start, stop at the first character they can't use, and return what they got — so malformed input doesn't fail, it silently truncates into a valid-looking number, which is worse than a crash because nothing downstream suspects it. Distinguish your converters: know which of your language's parsers are lenient (JavaScript's parseInt/parseFloat read partially) and which are strict (the Number conversion rejects the whole string, yielding NaN for '12abc') — and for any input where trailing garbage means the user made an error, use the strict path or validate the full string's shape first (a pattern check per the regex rules) so '12abc' is refused, not shortened. The rule of thumb: leniency is acceptable only when you deliberately want prefix extraction and can say so in a comment; everywhere else, the whole string must be the number. Pair this with the NaN and locale rules — strict rejection produces NaN, which you catch at the parse per those rules. Test converters with the three-headed input set: pure garbage, trailing garbage ('12abc'), and embedded garbage ('3.5.7'), confirming each is rejected, not trimmed. Only proceed once no user typo can survive conversion disguised as a smaller, cleaner number.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #817\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}