Skip to content

fix: escape backslashes in the filename when pushing a file - #2901

Draft
tonyandrewmeyer wants to merge 1 commit into
canonical:mainfrom
tonyandrewmeyer:fix/push-backslash-path
Draft

tonyandrewmeyer wants to merge 1 commit into
canonical:mainfrom
tonyandrewmeyer:fix/push-backslash-path

Conversation

@tonyandrewmeyer

Copy link
Copy Markdown
Collaborator

push() didn't escape backslashes in the multipart filename parameter, so Pebble treated a \ before another special character as an escape: back\\slash was written to the wrong path, and back\"slash or a name ending in \ failed with APIError: field name must be "files", got "". _encode_multipart now escapes \ before ", which is what Go's own multipart.Writer does (and what Pebble uses when it sends files for pull).

CR and LF in a path still aren't handled. They can't go in a quoted-string at all, and Go rejects them.

A property test of the multipart encoding (in #2869) found this. There's a unit test that checks the exact header bytes, and a real Pebble test that pushes and pulls a few awkward names.

Pebble reads the multipart Content-Disposition header with Go's
mime.ParseMediaType, where a backslash in a quoted string escapes the next
character if it's a tspecial. Only double quotes were escaped, so a path with
a backslash before a tspecial arrived at Pebble as a different path, and a
path ending in a backslash made the header unparsable. Escape backslashes as
well, the same way Go's multipart.Writer does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant