-
Notifications
You must be signed in to change notification settings - Fork 12
fix:non-string values #616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@flatfile/plugin-xlsx-extractor': patch | ||
| '@flatfile/util-extractor': patch | ||
| --- | ||
|
|
||
| This release fixes an issue when using `raw` or `rawNumbers` with non-string values in the header row. |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -237,6 +237,9 @@ export function keysToFields({ | |||||||||||||
| { count: number; index: number; metadata?: { fieldRef: string } } | ||||||||||||||
| > = keys.reduce((acc, key) => { | ||||||||||||||
| if (!key) key = '' | ||||||||||||||
| if (typeof key !== 'string') { | ||||||||||||||
| key = String(key) | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+240
to
+242
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Approve changes with a minor suggestion for improvement The added type check and string conversion effectively address the issue of non-string values in the header row, which aligns with the PR objectives. This change should resolve the XLSX file extraction failures mentioned in the linked issue #1583. Consider adding a more robust type conversion to handle potential edge cases: if (typeof key !== 'string') {
- key = String(key)
+ key = typeof key === 'object' && key !== null ? JSON.stringify(key) : String(key)
}This modification ensures that complex objects are properly stringified, providing more meaningful header values in such cases. Committable suggestion
Suggested change
Tip Codebase Verification Potential Issues Found with Non-String Key Processing The verification revealed multiple instances where keys are processed without explicit type checking or conversion. It's recommended to review these areas to ensure consistent and robust handling of non-string keys:
Ensure that all key manipulations include appropriate type checks or conversions to handle non-string values safely. Analysis chainSuggest comprehensive testing The changes look good and address the issue effectively. To ensure robustness, it would be beneficial to conduct comprehensive testing with various types of non-string header values (e.g., dates, numbers, booleans, and potentially nested objects). To assist with verification, you can use the following script to check for any remaining instances where non-string keys might be processed without conversion: This script will help identify areas in the codebase where keys are being processed, potentially without proper type checking. Review the results to ensure that appropriate safeguards are in place throughout the project. Update Verification Script to Correctly Target TypeScript Files The previous verification script encountered an issue recognizing the This script explicitly searches for Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for potential non-string key processing in the codebase
# Test 1: Search for direct key access or manipulation without type checking
echo "Test 1: Searching for potential unchecked key access..."
rg --type typescript --type javascript 'key\s*\.\s*(trim|toLowerCase|toUpperCase|replace|substring|slice)' -g '!*test*'
# Test 2: Search for array or object methods that might assume string keys
echo "Test 2: Searching for methods that might assume string keys..."
rg --type typescript --type javascript '(Object\.keys|Object\.entries|Object\.values|for\s*\(\s*\w+\s+in\s)' -g '!*test*'
echo "Review the results to ensure proper type checking is in place where necessary."
Length of output: 738 Script: #!/bin/bash
# Description: Check for potential non-string key processing in the codebase
# Test 1: Search for direct key access or manipulation without type checking
echo "Test 1: Searching for potential unchecked key access..."
rg --glob '*.ts' --glob '*.tsx' 'key\s*\.\s*(trim|toLowerCase|toUpperCase|replace|substring|slice)' -g '!*test*'
# Test 2: Search for array or object methods that might assume string keys
echo "Test 2: Searching for methods that might assume string keys..."
rg --glob '*.ts' --glob '*.tsx' '(Object\.keys|Object\.entries|Object\.values|for\s*\(\s*\w+\s+in\s)' -g '!*test*'
echo "Review the results to ensure proper type checking is in place where necessary."
Length of output: 4657 |
||||||||||||||
| key = key.trim() | ||||||||||||||
| if (key === '') { | ||||||||||||||
| key = 'empty' | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider revising empty value handling
The current implementation converts empty values to the string 'empty'. This approach might not be ideal in all scenarios, especially if distinguishing between truly empty values and the string 'empty' is important.
Consider allowing empty values to remain as empty strings or use a more distinct placeholder. For example:
This change would preserve the emptiness of the original value while still allowing for duplicate detection.
Committable suggestion