Fix Get-PnPFile mangling file names containing URL encoding sequences - #5413
Open
svermaak wants to merge 1 commit into
Open
Fix Get-PnPFile mangling file names containing URL encoding sequences#5413svermaak wants to merge 1 commit into
svermaak wants to merge 1 commit into
Conversation
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
This was referenced Jul 24, 2026
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.
Type of change
Related issues
Fixes #5010
Fixes #1864
What is in this Pull Request
Get-PnPFileunconditionally URL decoded the provided-Url. A file whose actual name contains an encoding sequence such as%20could 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%2Bbefore decoding), but any literal%XXsequence 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.txtandback compat.txt- each with distinct contents.Before: requesting the literal
test%20file.txtsilently returns the WRONG file's contentsAfter: literal name resolves to the correct file; space, plus and encoded-URL cases unchanged