Skip to content

fix(detect type): preserve whitespace-padded strings - #19299

Merged
fdncred merged 2 commits into
nushell:mainfrom
rajaryan0x1:fix/detect-type-whitespace
Oct 20, 2026
Merged

fdncred merged 2 commits into
nushell:mainfrom
rajaryan0x1:fix/detect-type-whitespace

Conversation

@rajaryan0x1

@rajaryan0x1 rajaryan0x1 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

In this PR I fixed #16872.

detect type matches some strings as numbers or booleans but fails when parsing them. It now keeps the original input and metadata when conversion fails, including integers that are too large to fit in i64.

Strings with leading or trailing whitespace now stay strings across all types, including durations. This follows panicbit’s suggestion in the issue discussion.

Numeric patterns now use ASCII digits, and booleans use ASCII case-insensitive matching. Integers with a leading + are supported, while numbers with mixed separators, such as "1,000_000", stay strings.

Updated the help text and regression tests. Each whitespace variant now runs as a separate test so failures are easier to identify.

Fixes #16872

User-facing changes (Release notes)

detect type preserves whitespace-padded strings

Fixed detect type returning conversion errors for whitespace-prefixed numbers, Unicode digits, and out-of-range integers. Inputs that fail conversion now remain unchanged.

Strings with leading or trailing whitespace, including durations such as " 5ns", now stay strings. Integers with a leading +, such as "+42", are now converted. Numbers with mixed comma and underscore separators remain strings.

Additional notes

Adds tested help examples and regression tests covering whitespace, Unicode inputs, integer boundaries, invalid dates, metadata preservation, and existing conversions.

Validation passed:

861 library tests, including command examples; 2 ignored
476 detect type integration tests
cargo fmt --all
cargo nuclippy
typos v1.51.1
git diff --check

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review overview

🟡 Changes recommended

Removing the leading \s* fixes " 42", but detect type still errors on any string that matches a pattern and then fails to parse, and durations still convert when padded.

Findings: 1 High severity · 3 Medium severity · 6 Low severity

Open (10)

Notes from my clanker, checked on 6eb7ff9. I didn't build the PR branch. Every repro above goes through code this PR doesn't change, and I ran them on nu 0.116.2.

@rajaryan0x1

Copy link
Copy Markdown
Contributor Author

@fdncred I have incorporated the changes you suggested and updated the pr. Could you take another look when you have time?

@rajaryan0x1
rajaryan0x1 requested a review from fdncred October 20, 2026 07:30
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Oct 20, 2026
@fdncred

fdncred commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Thanks

@fdncred
fdncred merged commit 7257a46 into nushell:main Oct 20, 2026
11 checks passed
@github-actions github-actions Bot added this to the v0.117.0 milestone Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

detect type: errors on whitespace-prefixed numbers

2 participants