Skip to content

fix: mis-parse of leading integer + space + unicode fraction#1

Open
akrigline wants to merge 1 commit into
magrinj:mainfrom
akrigline:fix/unicode-fraction-with-leading-integer-space
Open

fix: mis-parse of leading integer + space + unicode fraction#1
akrigline wants to merge 1 commit into
magrinj:mainfrom
akrigline:fix/unicode-fraction-with-leading-integer-space

Conversation

@akrigline

Copy link
Copy Markdown

Disclaimer if you care: Claude Code did a lot of the legwork on this. I noticed the issue working on a different project and figured I'd open a PR with its help.

Summary

Copying ingredients lists from allrecipies, I encountered lines like 1 ¼ cups milk.

"1 ¼ cups milk" lost its unit and left a stray "1" in the ingredient text, because unicodeFractionRegex only absorbed a digit into the match when it was directly adjacent to the fraction glyph.

Adding \s* between them lets it also match "1 ¼" so the leading integer is correctly stripped from the remainder before unit parsing runs.

Demonstrated by the new unit test

Without fix:

expect(parse('1 ¼ cups milk')).toEqual({
                              ^
error: expect(received).toEqual(expected)

  {
    "article": null,
-   "ingredient": "milk",
+   "ingredient": "1  cups milk",
    "maxQty": "1.25",
    "minQty": "1.25",
    "quantity": "1.25",
-   "symbol": "c",
-   "unit": "cups",
+   "symbol": null,
+   "unit": null,
  }

- Expected  - 3
+ Received  + 3

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • I have tested my changes
  • I have updated the documentation if needed
  • Lint, typecheck, and tests pass (bun run lint && bun run typecheck && bun run test)

"1 ¼ cups milk" lost its unit and left a stray "1" in the ingredient
text, because unicodeFractionRegex only absorbed a digit into the
match when it was directly adjacent to the fraction glyph. Adding
\s* between them lets it also match "1 ¼" so the leading integer is
correctly stripped from the remainder before unit parsing runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant