Closed yixiaco closed 1 month ago
I'm also seeing this problem, but with webdev 3.4.0 when the internet goes down
@lrhn – Did you do _SimpleUri
?
I did, and this is working as intended.
The URI github.com:443
has scheme github.com
and path 443
(.
is a valid character valid in schemes).
It has no authority part (host name, etc.) because an authority part must start with //
.
The author probably intended to get what they'd get by writing Uri.parse('https://github.com:443/')
, or maybe using Uri.https
.
The request.dart
code seems to assume that a URI path always starts with /
(the .substring(1)
intends to remove it). That's not necessarily true for a URI with no authority.
Thanks for clarifying, @lrhn !
That does mean that the shelf request.dart
file should probably be fixed. Line 352 can be changed to use, fx, .pathSegments.join('/')
instead of .path.substring(1)
, like some other code in the file already does.
I'd also check if line 340 can be made to pass -1
as the first argument to substring
.
That, or require paths to be absolute or there to be an authority component (explicit or implicit).
@lrhn – could you clarify a bit more here? I'm not sure I follow. Sounds like we should keep this open? Or file a new issue?
The issue here may be using a weird looking URI by accident, but it is a syntactically valid URI.
The code in this package assumes that a URI of that form cannot occur, which is why it does .path.substring(1); // Remove leading '/'
.
That assumption is wrong, and the example here shows such a URI reaching that code and removing a leading 4
.
We should either fix the code to not make unwarranted assumptions, or document and enforce that not all URIs are supported valid arguments, so that a URI with a path without a leading /
won't reach that code.
(Not sure it needs to be this issue, a more directly focused issue is probably easier to act on.)
Not sure what the ramifications of this issue are, like would end users who are requesting a normal endpoint see an issue? Or this this only happening for certain malformed URLs? For context, I'm running an API endpoint using shelf and I'm getting the exact same issue.
Guess it also doesn't help that _SimpleUri
doesn't have a toString() implementation given the "Instance of '_SimpleUri'" string.
_SimpleUri
has a toString
, but the error reporting code uses Error.safeToString
on it to avoid risking more errors while reporting errors.
The issue should only happen for certain "specially-formed" URIs. They're not malformed from the URI syntax perspective, but are maybe not what the author intended. Can you say which URIs you get the issue for? (If you catch the error, you may be able to get to the Uri
object inside and print its toString
.)
Where should I catch the error?
I'll admit I have no idea about the code of Shelf, just Uri
, so I can't say where an appropriate place to catch errors would be (or if they can be caught at all).
Not sure if @natebosch or @devoncarew or @brianquinlan is interested in digging into the root cause here at all.
1.Specific operations: Set up windows proxy server:
2.Then create http server
3.Use Chrome browser to visit github.com
I analyzed the source code and found that it was caused by this:
https://github.com/dart-lang/shelf/assets/30982989/f8b74e79-5a62-44b1-91cc-347b20c1a8dd