Skip to content

WEBDEV-8711 add type check and value conversion at the top of the function - #71

Open
dualcnhq wants to merge 1 commit into
mainfrom
webdev-8711-otp-fill-input
Open

WEBDEV-8711 add type check and value conversion at the top of the function#71
dualcnhq wants to merge 1 commit into
mainfrom
webdev-8711-otp-fill-input

Conversation

@dualcnhq

@dualcnhq dualcnhq commented Aug 6, 2026

Copy link
Copy Markdown

No description provided.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

🚀 View preview at
https://internetarchive.github.io/elements/pr/pr-71/

Built to branch ghpages at 2026-08-06 07:16 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 78.51%. Comparing base (b109f9f) to head (38fa302).

Files with missing lines Patch % Lines
src/elements/ia-otp-input/ia-otp-input.ts 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #71      +/-   ##
==========================================
- Coverage   78.62%   78.51%   -0.12%     
==========================================
  Files          17       17              
  Lines         697      698       +1     
  Branches      189      190       +1     
==========================================
  Hits          548      548              
  Misses        100      100              
- Partials       49       50       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

* Submits the result if enough characters are filled.
*/
private fillInputs(value: string) {
if (typeof value !== 'string') value = String(value ?? '');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This coerces anything, not just numbers. numericOnly defaults to true so the regex drops the garbage and we're fine in practice, but at numericOnly=false an object prefill becomes "[object Object]" and fills the boxes with objectO. Bailing reads safer than coercing for anything that isn't a string or a number:

if (typeof value === 'number') value = String(value);
if (typeof value !== 'string') return;

Also String(value ?? '') turns a null prefill into '', which then falls into clearInputs(). Probably what you want, just flagging it's a behavior change.

Q: was the number case the actual intent here, or just the easiest thing to test?

expect(inputs?.[5].value).to.equal('');
});

test('does not throw if prefill value property is set to a non-string value', async () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This covers the one path that never crashed. The reported error is handleInput reading e.data off beforeinput, not prefillValue. If we're hardening against a non-string reaching fillInputs, worth firing a beforeinput with a non-string data too:

const ev = new InputEvent('beforeinput', { bubbles: true });
Object.defineProperty(ev, 'data', { value: {} });
inputs?.[0].dispatchEvent(ev);

@jbuckner

jbuckner commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Left two inline notes.

Bigger picture though: I don't think this error is ours. Wrote it up on WEBDEV-8711 with the detail. Short version: fillInputs minifies to e.split(...) in the live offshoot bundle so it can't produce n.data.split, there's no .data.split( anywhere in our output, and the Sentry group it was filed from is a bucket of frameless browser-extension errors.

Happy to take this as hardening on its own merits, I just don't want it closing the ticket.

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.

3 participants