Skip to content

fix(rewrite): keep the minus sign on a line-initial negative number (#821) - #924

Open
Vaishnavi1709 wants to merge 1 commit into
mainfrom
fix/821-negative-number-minus-sign
Open

fix(rewrite): keep the minus sign on a line-initial negative number (#821)#924
Vaishnavi1709 wants to merge 1 commit into
mainfrom
fix/821-negative-number-minus-sign

Conversation

@Vaishnavi1709

Copy link
Copy Markdown
Collaborator

Summary

cleanRewriteLine stripped the minus off a line-initial negative number, so -5% churn reached the résumé — and the exported ATS PDF — as 5% churn. A reduction read as a gain, and nothing downstream looked wrong: the line stayed grammatical and the figure stayed plausible.

LIST_MARKER_PATTERN folded - and into one [•\-]\s* branch accepting zero trailing whitespace. Inside the fixed-point loop from #806, pass 1 removed the - marker and pass 2 read the uncovered - as a bullet glyph and removed it too; the bare -5% shape needed only one pass and predates the loop. This is the dash-side twin of the decimal bug #806 fixed on the numbered branch — the loop's own docblock warns that "any strip added to this loop must be checked the same way", and the -/ branch was carried over without that check.

The fix splits the two glyphs apart and withholds the zero-space branch from - when a number follows:

-const LIST_MARKER_PATTERN = /^(?:\d+[.)]\s+|[•\-]\s*|\*\s+)/;
+const LIST_MARKER_PATTERN = /^(?:\d+[.)]\s+|•\s*|-(?:\s+|(?!\.?\d))|\*\s+)/;

keeps \s* because it is only ever a glyph, never part of the text it precedes. - is the one marker that doubles as ordinary content.

Closes #821

Deviation from the fix proposed on the issue

Worth flagging explicitly, since the issue body specifies a different regex.

The suggested -(?:\s+|(?=[A-Za-z])) regresses an existing test: it stops stripping the tight -**Led** the migration of billing. case pinned at post-process.test.ts:194 ("tight dash, no space"), because * is not a letter, so the lookahead fails and the marker survives. Caught by simulating the fixed-point loop over every existing marker case before writing code.

A negative lookahead on the number is the property actually wanted, and (?!\.?\d) additionally covers -.5% as well as -5%.

Review focus

  • src/lib/webllm/post-process.ts:127 — the \s+ branch is deliberately left unguarded, on the reasoning that - 5% is a marker plus a positive number and a genuine negative is written - -5%. Is there a shape where a model emits - followed by an intended negative with no second sign?
  • src/lib/webllm/post-process.ts:127(?!\.?\d) is a lookahead, so a tight - before a non-number still strips as before. Does that hold for every non-letter opener the rewrite path can emit (-**Led**, -"quoted", -(paren))?

Test plan

  • npm run typecheck clean
  • npm run lint clean
  • npm run verify green (also re-run by the pre-push hook)
  • Full suite green — 383 files / 6457 tests passed, 8 skipped. Run explicitly rather than relying on verify's scoped test:changed selection.
  • New cases falsified against the pre-fix pattern — reverting only the regex turns all 7 new assertions red, the other 51 in the file stay green.
  • All four repro lines from the issue fixed; -Shipped X, -**Led**, • 4.2%, - 3.5x, 1. Foo and *Foo.* unchanged.

Six negative-number rows join the decimal-preservation it.each table — the table that already asserts this property for the numbered branch — plus a sign-preservation property test across all five marker shapes.

No fixture binaries touched, so the fixture-PII preflight does not apply.

…821)

`cleanRewriteLine` stripped the minus off a line-initial negative number,
so `-5% churn` reached the résumé — and the exported ATS PDF — as
`5% churn`. A reduction read as a gain, and nothing downstream looked
wrong: the line stayed grammatical and the figure stayed plausible.

`LIST_MARKER_PATTERN` folded `-` and `•` into one `[•\-]\s*` branch that
accepted zero trailing whitespace. Inside the fixed-point loop #806 added,
pass 1 removed the `- ` marker and pass 2 read the uncovered `-` as a
bullet glyph and removed it too; the bare `-5%` shape needed only one pass
and predates the loop. This is the dash-side twin of the decimal bug #806
fixed on the numbered branch, which the loop's docblock already warns
about — the `-`/`•` branch was carried over without the same check.

Split the two glyphs apart and withhold the zero-space branch from `-`
when a number follows: `-(?:\s+|(?!\.?\d))`. `•` keeps `\s*` because it
is only ever a glyph, never part of the text it precedes.

Note the fix differs from the one suggested on the issue. A positive
`(?=[A-Za-z])` lookahead regresses the tight `-**Led** the migration`
case pinned at post-process.test.ts:194, since `*` is not a letter. The
negative lookahead on the number is the property actually wanted, and it
covers `-.5%` as well as `-5%`.

Six negative-number rows join the decimal-preservation `it.each` table —
the table that already asserts this property for the numbered branch —
plus a sign-preservation property test across all five marker shapes. All
seven fail against the pre-fix pattern.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying offlinecv with  Cloudflare Pages  Cloudflare Pages

Latest commit: f152fae
Status: ✅  Deploy successful!
Preview URL: https://5ca556be.offlinecv.pages.dev
Branch Preview URL: https://fix-821-negative-number-minu.offlinecv.pages.dev

View logs

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.

cleanRewriteLine eats the minus sign off a line-initial negative number (-5% churn5% churn)

1 participant