Repository navigation
fix(detect type): preserve whitespace-padded strings - #19299
Merged
Merged
Conversation
fdncred
reviewed
Oct 19, 2026
Contributor
There was a problem hiding this comment.
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
Open (10)
A pattern match followed by a failed parse still errors\dmatches non-ASCII digits thatparserejects Integers pasti64matchINTEGER_REand then error Durations still accept surrounding whitespace Mixed,and_delimiters are accepted Case-insensitive matching foldsſtos, and the error message is backwards"+3.14"converts but"+42"stays a string Example description says "around" but shows only a leading space The nested loops hide which variant failed The delimited-integer error shows the stripped string. In theINTEGER_WITH_DELIMS_REbranch (lines 285-296),val_stris shadowed by the copy with,and_removed before the error is built."999,999,999,999,999,999,999" | detect typereports"999999999999999999999" does not represent a valid integer value, which isn't what the user typed. Keep the original for the help text, or let the fallback in the first comment remove this error.
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.
Contributor
Author
|
@fdncred I have incorporated the changes you suggested and updated the pr. Could you take another look when you have time? |
Contributor
|
Thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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 typepreserves whitespace-padded stringsFixed
detect typereturning 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: