fix: fix formatting of whitespace-only values #1237
Merged
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.
This PR fixes a bug in the formatting logic where values containing only whitespace characters (spaces, tabs, newlines) were being incorrectly formatted as empty strings instead of being properly quoted.
Problem
When formatting values that consisted entirely of whitespace characters, the auto-trim functionality would remove all content, resulting in empty output. This was incorrect because:
Solution
The fix introduces a flexible auto-trim mechanism with flags:
AutoTrimFlagenum with aPreserveWhiteSpaceOnlyflag to control trimming behaviorWithAutoTrimtrait to accept flags that determine whether whitespace-only content should be preservedValueFormatAutoto preserve whitespace-only values by passing thePreserveWhiteSpaceOnlyflag" ","\t\t")Changes
Core formatting logic (
src/formatting.rs):WithAutoTrimtrait accept anAutoTrimFlagsparameterAutoTrimFlagenum withPreserveWhiteSpaceOnlyvariant usingEnumSetwith_auto_trimimplementation to check flags before truncating whitespace-only contentValueFormatAutoto preserve whitespace-only values while still trimming trailing whitespace from mixed contentTests (
src/formatting/tests.rs):" "now formats as" "instead of empty string)This fix ensures that all values, including those containing only whitespace, are formatted correctly and unambiguously, improving data integrity and user experience.