Skip to content

Fix Get-PnPFile mangling file names containing URL encoding sequences - #5413

Open
svermaak wants to merge 1 commit into
pnp:devfrom
svermaak:fix/get-pnpfile-literal-encoded-url
Open

Fix Get-PnPFile mangling file names containing URL encoding sequences#5413
svermaak wants to merge 1 commit into
pnp:devfrom
svermaak:fix/get-pnpfile-literal-encoded-url

Conversation

@svermaak

Copy link
Copy Markdown
Contributor

Type of change

  • Bug fix

Related issues

Fixes #5010
Fixes #1864

What is in this Pull Request

Get-PnPFile unconditionally URL decoded the provided -Url. A file whose actual name contains an encoding sequence such as %20 could therefore not be retrieved: the cmdlet decoded the name to a space and either failed with file not found or, worse, silently returned the contents of a different file that happened to match the decoded name. The + character had a partial workaround in place (pre-encoding it to %2B before decoding), but any literal %XX sequence in a file name remained broken.

With this change the Url is tried exactly as provided first. Only when no file exists at that path does the cmdlet fall back to the decoded form, so URLs copied from a browser address bar keep working exactly as before. The resolution happens once, ahead of the parameter set switch, so all output modes (-AsFile, -AsString, -AsListItem, -AsFileObject, -AsMemoryStream) benefit.

Reproduction and verification

Verified against a SharePoint Online library containing test%20file.txt (literal name), test file.txt, a+b.txt and back compat.txt - each with distinct contents.

Before: requesting the literal test%20file.txt silently returns the WRONG file's contents

Before the fix

After: literal name resolves to the correct file; space, plus and encoded-URL cases unchanged

After the fix

Get-PnPFile unconditionally URL decoded the provided Url, so a file whose
actual name contains an encoding sequence such as %20 could not be
retrieved: the cmdlet decoded it to a space and either failed with file not
found or silently returned a different file. The + character had a partial
workaround but any literal %XX sequence was broken.

The Url is now tried exactly as provided first. Only when no file exists at
that path is the decoded form used, keeping URLs copied from a browser
address bar working as before.

Fixes pnp#5010
Fixes pnp#1864
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant