Add defensive check for data URL prefix in summarizeDataUrl - #1264
Open
pavankumar-vh wants to merge 1 commit into
Open
Add defensive check for data URL prefix in summarizeDataUrl#1264pavankumar-vh wants to merge 1 commit into
pavankumar-vh wants to merge 1 commit into
Conversation
The summarizeDataUrl function was called from summarizeLargeValue which checks if a string starts with 'data:' before calling it. However, if summarizeDataUrl were ever called from a different context or if the prefix check were removed, the function would incorrectly try to parse non-data-URL strings. Added a defensive check at the start of summarizeDataUrl that returns the value unchanged if it doesn't start with 'data:'. This makes the function safer to use independently and prevents incorrect parsing of malformed inputs. Also added comprehensive test coverage demonstrating: 1. Valid data URLs are properly summarized 2. Non-data-URL strings pass through unchanged 3. Edge case: data URL-like strings without comma are handled gracefully All 3 tests pass.
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.
Overview
Add a defensive check for the data URL prefix in
summarizeDataUrlfunction incommon/src/util/cache-debug.ts.Bug Description
The
summarizeDataUrlfunction was called fromsummarizeLargeValuewhich checks if a string starts withdata:before calling it. However, ifsummarizeDataUrlwere ever called from a different context or if the prefix check were removed, the function would incorrectly try to parse non-data-URL strings, potentially producing misleading summaries.Fix
Added a defensive check at the start of
summarizeDataUrlthat returns the value unchanged if it doesn't start withdata:. This makes the function safer to use independently and prevents incorrect parsing of malformed inputs.Testing
Added comprehensive test coverage demonstrating:
All 3 tests pass.
Files Changed
common/src/util/cache-debug.ts- Added defensive prefix checkcommon/src/util/__tests__/cache-debug.test.ts- New test file with 3 test casesScope
This change only touches
common/which is an approved contribution area per the Contributing Guide.