Problem/Motivation
I'm a bit confused by #2372507-74: Remove _system_path from $request->attributes.4 (leading /) and the changes based on that. At least, we need to fix the documentation in CurrentPathStack::getPath() because that still says it returns it without a leading /, and given that it is 50/50 when we need a leading / it, maybe there should be an easier way to get the path without leading /?
IMHO, leading / was always a good way to differentiate between a url string (which is yet another thing, as commented above, it also includes the subfolder you're in) and the path. We need to better explain who should be using it and when, the current explanation there reads like an excuse for it's existence :)
Proposed resolution
Remaining tasks
User interface changes
API changes
Comments
Comment #1
dawehnerGood catch, yeah that got forgotten after the review of crell.
Comment #2
zealfire commentedComment #3
zealfire commentedI have made changes in the documentation after deducing that we just need to return path without mentioning that / will be trimmed.Have i deduced correct ?.Please review.
Thanks
Comment #4
zealfire commentedChanging the status.
Comment #5
berdirI think we should explicitly mention that it includes the leading /.
Comment #6
zealfire commentedMade changes according to comment 5.Please review.
Thanks.
Comment #7
berdirAfter some discussions with @dawehner, it make make sense to have some more documentation on what this actually is. like aliased vs unaliased, and language prefix. Possibly explicitly describe the differences between getPathInfo() and this.
Also, the last sentence in the Note is a typical @dawehner sentence, I'm not sure we should document a service class like that :)
Comment #8
jhodgdonHm. I was asked to comment here. The current patch looks fine as far as it goes.
I'll follow additional patches... I am all for more clear documentation on what is being returned, of course! Sounds like this is Needs Work for #7?
Comment #9
Crell commentedAgreed with Berdir and jhodgdon. Standardize on leading / everywhere, fix this doc, and possibly improve the doc for which path we're talking about.
Comment #10
kerby70 commentedI am suggesting:
getPath() calls getPathInfo() that has:
Two more levels in getRequestUri() has:
Comment #11
jhodgdonThanks for the new patch... but it does not address the questions in #7. I am also not sure it is accurate... or at least I think using the term "URI decoded" is misleading (it sounds to me as though it's about urlencode/urldecode, and that is not related to what these functions do).
Comment #12
cilefen commentedComment #13
mglamanHere is a patch which fixes documentation on trailing slash, and brings over urldecoded notes from Request::getPathInfo().
Comment #14
jhodgdonOK, I'm pretty confused now.
I was attempting to review the patch here to see if it was accurate... I decided that it doesn't merit a Novice tag until we sort out what is happening. Sorry mglaman -- you followed the instructions (thanks!) but I am not sure the patch is the correct documentation.
So.
CurrentPathStack::getPath(), if you look at the code, is returning the result of a \Symfony\Component\HttpFoundation\Request::getPathInfo() call, which says "always starts with \".
However, what it actually does is to return the result of a call to its preparePathInfo() method. This method returns "\" if it can't figure out the path, and otherwise it strips getBaseUrl() off the request URL and returns that.
The base URL comes from the prepareBaseUrl() method. It looks as though this method always strips off the last / so that getPath() should always start with a / no matter what.
So I'm very confused about this issue. What makes you think that CurrentPathStack::getPath() has the wrong documentation? I must have missed something...
Comment #15
dawehnerAdding a related issue
Comment #17
mgiffordComment #24
deviantintegral commentedI'm seeing different behaviour if a node has a path alias. When the path alias is used, the returned path has a leading slash. I'm not 100% sure, but since
\Drupal\Core\Url::fromUserInputrequires a leading slash this gets pretty confusing.Here's two patches - one with the docs fix, and the other that throws a \LogicException. Since this method itself doesn't I'm not 100% sure that the path alias is the cause, so I'd like to see if this fails any tests.
Comment #26
deviantintegral commentedHuh, not running tests on CS fails is new. That's too bad, it adds a roadblock to running tests like this.
\Drupal\Core\Path\CurrentPathStack::setPath()doesn't ensure that the leading slash is set, unlike\Symfony\Component\HttpFoundation\Request::getPathInfo. That means that for routes,\Drupal\Core\Routing\RouteProvider::getRouteCollectionForRequestends up setting paths with the leading slash. The easiest way to see this is to set a breakpoint withstrpos($path, '/') === 0;at the uncachedsetPathcall in getRouteCollectionForRequest. Clear caches from the UI, and you'll see them being set.My initial thought was to treat the docs as correct, but stripping the leading slash in setPath() hoses the site.
Here's a patch that validates incoming paths in setPath. If all the tests pass I think we can call this a docs bug. I don't think this is a hard BC break because there's no interface defined, but it's certainly one worth calling out.
Comment #27
dawehnerDo you mind elaborating a bit more on that? I could imagine that throwing an exception here is problematic too. Maybe triggering an error / having an assert would be a better approach to not cause 500s on production, which leads to really problematic behaviours on reverse proxies.
Comment #28
deviantintegral commentedHere's the exception thrown when clearing caches with the attached patch that instead removes any leading slashes. I'm guessing this will cause a ton of test fails.
Comment #30
deviantintegral commentedBack to review for the patch in #26.
Comment #37
smustgrave commentedSeems there were some errors in #28 from what I can tell. Least the tests aren't green.