-
Notifications
You must be signed in to change notification settings - Fork 21
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
parse() does not handle custom protocol with root slash, like whatever:///whatever #11
Comments
Hi! My goal is definitely to support as many schemes as possible. I was under the impression that parse_url worked fine for a bunch of different schemes. At the very least I question the validity of both those urls. As far as I can tell a triple-slash in ftp uri's is not allowed. The ssh uri is not officially registered anywhere, and I also question if it's correct. The colon in particular is weird. The only draft spec for the ssh uri I could find actually uses the format |
There is a difference between URL and URI:
A valid URI is anything that follows has this form:
There is no constraint on what schemes are allowed. What I gave were just examples, they don't have to be syntactically correct according to the scheme, but they are syntactically correct according to the definition of URIs. For example, I could invent my own URI protocol:
and that would be a valid URI, but You might think this is not a big use case but my language server gets URIs from the outside and the only thing I know is that they are valid URIs, not the protocol. VS Code for example sends new files with a URI like |
That last example you gave actually parses just fine again, because it's valid. Can you give an example of a URI that's valid and does not parse? |
\Sabre\Uri\parse('whatever:///whatever'); Seems to be related to the root slash - which works fine for |
I had to do a bunch of digging but eventually found this:
So the triple slash issue is a legit one. I wouldn't go as far as saying that the library only parsers URLs and not URIs though, but rather that it can't parse a URI with an empty hostname if it's not a file: scheme. |
Yep, sorry. I just saw that comment on |
For my use case it would be enough if it doesn't parse, but at least doesn't generate an Error - I think it is a PHP4-style error, so we could silence it with |
Marking this as a bug, but I want to say that given your situation Sabre\Uri simply not be the best choice. One reason for this is that this:
Could technically pass as a valid uri.. maybe? I'm not even sure. 1 here will be interpreted as the host name. If I understand this URI correctly, this really should have been something like this:
But ideally even this: urn:x-vendorname:inmemory:1 If you run into URIs of the first kind, and you don't expect just any uri, the thing you are actually probably interested in is:
In that case you might simply be better off doing a split on Just a thought! I still want to fix this though, even though it's a bit depressing because the solution to this means a custom parser which is gonna be slower for the 99.99% use-case. |
@evert I agree with you - I think a URN would be a better fit for this. But I get these from the client and can't control them. What I am actually interested in is only the path, I need to match it against a few conditions. It's okay if the condition doesn't match because |
I would ideally like the API to parse any valid URI you throw at it, but always throw an exception for those that aren't. What's stopping you from catching the exception and handling it that way? |
Seems a bit weird to use |
What about a try..catch block? Don't use |
It's a PHP4-style error iirc. You can only catch it if you have an error handler registered, and that is an assumption I don't want to make. Maybe Sabre could |
I see, yes that would be perfect! Totally agree with that idea |
This is a new implementation of PHP's parse_url. It's likely not perfect, but it catches specific cases that the built-in function does not support. Fixes Issue #9 Fixes Issue #11 @felixfbecker / @sii / @PVince81 Does this sufficiently solve your problem?
This is a new implementation of PHP's parse_url. It's likely not perfect, but it catches specific cases that the built-in function does not support. Fixes Issue #9 Fixes Issue #11 @felixfbecker / @sii / @PVince81 Does this sufficiently solve your problem?
As this package is called sabre/uri, and not sabre/url, I expected it to handle any valid URI. For example, it should handle any URI scheme. However, that is not the case, because it uses
parse_url
internally. The docs clearly say thathttp://
andfile://
work, any other URI results in anErrror: Unsupported operand types
.Examples:
This really limits the usefulness of this function.
The text was updated successfully, but these errors were encountered: