thephpleague / uri-src

URI manipulation Library
https://uri.thephpleague.com
MIT License
27 stars 8 forks source link

Windows UNC #132

Closed medilies closed 8 months ago

medilies commented 8 months ago

Feature Request

Q A
Package League\Uri\Uri
New Feature yes
BC Break no

Proposal

I am not sure if Windows UNCs are fully compatible with URIs and able to be converted back and forth.

If they are. A fromUnc constructor would be a great addition.

References:

nyamsprod commented 8 months ago

@medilies did you had a chance to read the documentation ? There you will see the following:

<?php

use League\Uri\Uri;

$uri = Uri::fromWindowsPath('c:\windows\My Documents\my word.docx');
echo $uri; //returns 'file://localhost/c:My%20Documents/my%20word.docx'

You should play around with it to see if everything is supported. If not a PR to complement the feature is more than welcome. It will get review, evaluated and perharps merged.

medilies commented 8 months ago

@nyamsprod thank you for taking the time to respond to me.

First, I want to confirm that I checked the docs and the source code of the package. And add a note that UNCs must be network locations and not local paths.

After a day of researching UNCs, I am not sure if a function that handles paths should be capable of fully handling UNCs.

All the following are examples gathered from Wikipedia and MS docs highlighting their expected URL counterpart, and the output of this package using Laravel tinker.

In the first table, the expected output is how Google Chrome transforms the input in the search bar.

input expected output (string)League\Uri\Uri::fromWindowsPath($v)
\\ComputerName\SharedFolder\Resource file://ComputerName/SharedFolder/Resource Error Class "League\Uri\Idna\Converter" not found.
\\10.0.0.2\SharedFolder\Resource file://10.0.0.2/SharedFolder/Resource file://10.0.0.2/SharedFolder/Resource
ComputerName\SharedFolder\Resource (invalid, treated as search) ComputerName/SharedFolder/Resource
\\system07\C$\ file://system07/C$/ file://system07/C%24/
\\system07\C:\ file://system07/C:/ (invalid) file://system07/C%3A/
\\system07\C$ file://system07/C$ file://system07/C%24
\\Server2\Share\Test\Foo.txt file://Server2/Share/Test/Foo.txt Error Class "League\Uri\Idna\Converter" not found.

In the second table, the expected output is my effort to translate DOS paths that aren't supported by Chrome.

input expected output (string)League\Uri\Uri::fromWindowsPath($v)
\\?\UNC\ComputerName\SharedFolder\Resource file://ComputerName/SharedFolder/Resource League\Uri\Exceptions\SyntaxError The host%3Fis invalid : a registered name can not contain URI delimiters or spaces.
\\.\UNC\LOCALHOST\c$\temp\test-file.txt file://LOCALHOST/c$/temp/test-file.txt file://./UNC/LOCALHOST/c%24/temp/test-file.txt
\\.\c:\temp\test-file.txt (invalid) file://./c%3A/temp/test-file.txt

So I seek your expertise just to adjust what I have learned today. And I would be more than happy to improve/fix fromWindowsPath or contribute with a new method.

nyamsprod commented 8 months ago

@medilies I am no expert in UNC but AFAIK they are partially (maybe) fully supported in the package see https://github.com/thephpleague/uri-src/blob/78111954bc35ecd7c13314704125fe2a058e66e9/uri/FactoryTest.php#L217 So I as say try to add more tests if needed to improve the already present feature if you see a need for better support.