Fix data URL validation in summarizeDataUrl - #1230
Conversation
The summarizeDataUrl function assumed the value started with 'data:' (5 chars) and sliced from index 5 to extract the media type. If the value didn't start with 'data:', this would return incorrect results. Added a check to ensure the header starts with 'data:' before slicing, returning 'unknown' as the media type if it doesn't.
|
Thanks for the contribution. The change itself is safe and in-scope ( If you found a path where As it stands this is low-risk but not clearly necessary — happy to reconsider with a concrete before/after example or a test. |
Overview
Fix a potential bug in the
summarizeDataUrlfunction incommon/src/util/cache-debug.ts.Bug Description
The
summarizeDataUrlfunction assumed the value started withdata:(5 characters) and sliced from index 5 to extract the media type. If the value didn't start withdata:, this would return incorrect results.Fix
Added a check to ensure the header starts with
data:before slicing, returning'unknown'as the media type if it doesn't.Testing
No existing tests for this function, but the fix prevents incorrect behavior with malformed data URLs.
Files Changed
common/src/util/cache-debug.ts- Added data URL validationScope
This change only touches
common/which is an approved contribution area per the Contributing Guide.