Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] potential bug with files containing %20 in the file name #4370

Open
tiagoduarte opened this issue Oct 2, 2024 · 1 comment · May be fixed by #4480
Open

[BUG] potential bug with files containing %20 in the file name #4370

tiagoduarte opened this issue Oct 2, 2024 · 1 comment · May be fixed by #4480
Labels
bug Something isn't working

Comments

@tiagoduarte
Copy link

tiagoduarte commented Oct 2, 2024

I have performed extensive testing to at least within reason, ensure that this is not something I am going.

System:
Microsoft Windows Server 2019 Standard
10.0.17763
PS 7.4.5
PnP.PowerShell 2.12.0

Here are the exact steps to reproduce the issue:

create a file and ensure that in the name, it contains the literal characters "%20", for example "test%20file.txt"
(which is something that is now allowed to happen)

pre-check 1) check the copied "path" from the properties, it will look like this,
https://contoso.sharepoint.com/teams/testsite/testlibrary/test%2520file.txt
the file will open, via UI, without any problems

pre-check 2) use site search to locate the document, which will show it and open correctly via search

now let's run some scripts and see how the different errors appear

error path 1: get-pnpfile aslistitem

connect-pnponline -url $site -Interactive
get-pnpfile -url "https://contoso.sharepoint.com/teams/testsite/testlibrary/test%2520file.txt" -aslistitem

output:
Get-PnPFile: The object specified does not belong to a list.

error path 2: search results

$searchQuery = '(IsDocument:True AND path:https://contoso.sharepoint.com/teams/testsite/testlibrary)'
$searchResults = Submit-PnPSearchQuery -Query $searchQuery -MaxResults 500 -StartRow 0
write-host $searchResults.ResultRows.Path

output:
https://contoso.sharepoint.com/teams/testsite/testlibrary/test%20file.txt

note: this is already a red flag. the path is not encoded properly and will not work

get-pnpfile $searchResults.ResultRows.Path

output:
Get-PnPFile: File Not Found.

error path 3: file properties

connect-pnponline -url $site -Interactive
$file = get-pnpfile -url "https://contoso.sharepoint.com/teams/testsite/testlibrary/test%2520file.txt"
#note: so far, no errors
$context.load($file.ListItemAllFields)
$context.ExecuteQuery()

output:
MethodInvocationException: Exception calling "ExecuteQuery" with "0" argument(s): "The object id "site:REDACTED:web:REDACTED:file:/teams/testsite/https://contoso.sharepoint.com/teams/testsite/testlibrary/test%20file.txt" is invalid."

appreciate any help.

I'm not sure if this qualifies for a ticket, since it is likely related to the pnp commands and everything works within the user interface

@tiagoduarte tiagoduarte added the bug Something isn't working label Oct 2, 2024
@koskila
Copy link
Contributor

koskila commented Oct 25, 2024

I think this is because you're using an absolute URL for Get-PnpFile instead of server-relative URL. I suppose the commandlet should either validate that it's not given an absolute URL, or just change absolute URLs to relative ones.

Based on my quick testing, the latter works fine in this case, but I'm not sure the commandlet should take the responsibility. Any thoughts, @gautamdsheth ?

koskila added a commit to koskila/pnppowershell that referenced this issue Oct 25, 2024
@koskila koskila linked a pull request Oct 26, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants