Skip to content

fix: don't double multi-part extensions when saving files - #2303

Closed
serhiizghama wants to merge 2 commits into
ChromeDevTools:mainfrom
serhiizghama:fix/ensure-extension-multipart
Closed

serhiizghama wants to merge 2 commits into
ChromeDevTools:mainfrom
serhiizghama:fix/ensure-extension-multipart

Conversation

@serhiizghama

Copy link
Copy Markdown
Contributor

Saving a performance trace to a compressed path like trace.json.gz (the exact example in the performance_start_trace/performance_stop_trace schema) writes it to trace.json.json.gz instead.

The cause is in ensureExtension: it strips the current extension with path.extname and re-appends the target one, but path.extname("trace.json.gz") only returns .gz. So it strips .gz → trace.json, then appends .json.gz → trace.json.json.gz. The compressed-trace tools pass .json.gz as the extension, so this hits any trace saved to a .gz path.

Fix is to skip the strip-and-reappend when the path already ends with the requested extension. Single-segment extensions and the replace-a-different-extension case (e.g. result.jpg → .png) are unchanged; added a couple of cases to the existing ensureExtension test to lock in the .json.gz behavior.

path.extname only strips the last segment, so saving a trace to
trace.json.gz produced trace.json.json.gz. Skip the strip/re-append
when the path already ends with the requested extension.

@OrKoN OrKoN left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. It looks like some tests fail but I also wonder let's just enforce .gz instead of .json.gz?

@OrKoN

OrKoN commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

I have opened a PR for that #2303

@OrKoN OrKoN closed this in #2305 Jul 6, 2026
jozef-javorsky-dodo pushed a commit to jozef-javorsky-dodo/chrome-devtools-mcp that referenced this pull request Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants