thephpleague / uri-src

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

KDE environment file URIs #130

Closed medilies closed 10 months ago

medilies commented 10 months ago

Bug Report

Information Description
Package League\Uri\Uri
Version 7.3
PHP version 8.1.6
OS Platform Windows

Summary

I was looking at this Wikipedia page https://en.wikipedia.org/wiki/File_URI_scheme and tried all the examples. The package fails to parse the The KDE environment example file:/etc/fstab

Standalone code, or other way to reproduce the problem

<?php

use League\Uri\Uri;

require __DIR__.'/../vendor/autoload.php';

var_dump(Uri::new('file:/etc/fstab')->getPath());

Expected result

/etc/fstab

Actual result

PHP Fatal error:  Uncaught League\Uri\Exceptions\SyntaxError: The uri `file:/etc/fstab` is invalid for the `file` scheme. in C:\Dev\row-bloom\examples\vendor\league\uri\Uri.php:827
Stack trace:
#0 C:\Dev\row-bloom\examples\vendor\league\uri\Uri.php(239): League\Uri\Uri->assertValidState()
#1 C:\Dev\row-bloom\examples\vendor\league\uri\Uri.php(406): League\Uri\Uri->__construct('file', NULL, NULL, NULL, NULL, '/etc/fstab', NULL, NULL)
#2 C:\Dev\row-bloom\examples\uri\index.php(7): League\Uri\Uri::new('file:/etc/fstab')
#3 {main}
  thrown in C:\Dev\row-bloom\examples\vendor\league\uri\Uri.php on line 827

Fatal error: Uncaught League\Uri\Exceptions\SyntaxError: The uri `file:/etc/fstab` is invalid for the `file` scheme. in C:\Dev\row-bloom\examples\vendor\league\uri\Uri.php:827
Stack trace:
#0 C:\Dev\row-bloom\examples\vendor\league\uri\Uri.php(239): League\Uri\Uri->assertValidState()
#1 C:\Dev\row-bloom\examples\vendor\league\uri\Uri.php(406): League\Uri\Uri->__construct('file', NULL, NULL, NULL, NULL, '/etc/fstab', NULL, NULL)
#2 C:\Dev\row-bloom\examples\uri\index.php(7): League\Uri\Uri::new('file:/etc/fstab')
#3 {main}
  thrown in C:\Dev\row-bloom\examples\vendor\league\uri\Uri.php on line 827
nyamsprod commented 10 months ago

@medilies thanks for using the package. What you are describing is not a bug per se but the application of another RFC https://datatracker.ietf.org/doc/html/rfc8089#appendix-A which is still in proposed state. If you are willing to provide a PR to support your expected behaviour I would be more than glad to review and merge it in the package

nyamsprod commented 10 months ago

@medilies the easiest way to add this feature would be to add two methods:

It would enable the feature without adding any BC break.

medilies commented 10 months ago

Thank you so much for showing me how to contribute while handling my issue 🙏🏼 I hope to be able to make use of this help and be a better contributor in the futur.