Skip to content
New issue

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

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

Already on GitHub? # to your account

$URI::file::DEFAULT_AUTHORITY #92

Open
jackdeguest opened this issue Nov 30, 2021 · 1 comment
Open

$URI::file::DEFAULT_AUTHORITY #92

jackdeguest opened this issue Nov 30, 2021 · 1 comment

Comments

@jackdeguest
Copy link

When URI::file is loaded then calling, for example, URI::file::Win32->new( q{C:\Documents\Some\Document.pdf} ) will not work as expected, because URI::file::Win32->_file_extract_authority has a condition whether $URI::file::DEFAULT_AUTHORITY is defined and $URI::file::DEFAULT_AUTHORITY is set in URI::file to an empty string, hence defined, thus the condition always returns true if URI::file is loaded.

As an example, consider:

perl -MURI -MURI::file::Win32 -lE 'say URI::file::Win32->new( q{C:\Documents\Some\Document.pdf} )'

would yield file://C:/Documents/Some/Document.pdf and calling path would rightfully produces /Documents/Some/Document.pdf

However, if I load URI::file, then look what happens:

perl -MURI -MURI::file -MURI::file::Win32 -lE 'say URI::file::Win32->new( q{C:\Documents\Some\Document.pdf} )->path'

This would yield: file:///C:/Documents/Some/Document.pdf and calling path would produce: /C:/Documents/Some/Document.pdf

The recommended solution would be to set the value of $URI::file::DEFAULT_AUTHORITY to undef, or leave it undefined and then it would work.

@choroba
Copy link

choroba commented Feb 4, 2022

Undefining the default authority (regardless whether in URI::file or URI::file::Win32) breaks t/file.t:

t/file.t .. 
1..12
ok 1
URI::file->new('/foo/bar', 'unix') ne file:///foo/bar, but file:/foo/bar
URI::file->new('\foo\bar', 'win32') ne file:///foo/bar, but file:/foo/bar
not ok 2
ok 3
ok 4
ok 5
ok 6
URI::file->new('/A:/', 'unix') ne file:///A:/, but file:/A:/
URI::file->new('A:\', 'win32') ne file:///A:/, but file://A:/
not ok 7
URI::file->new('/', 'unix') ne file:///, but file:/
URI::file->new('\', 'win32') ne file:///, but file:/
not ok 8
ok 9
ok 10
ok 11
ok 12
Failed 3/12 subtests 

Test Summary Report
-------------------
t/file.t (Wstat: 0 Tests: 12 Failed: 3)
  Failed tests:  2, 7-8

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants