Problem/Motivation
Selecting 'Use path alias' in contextual filter results in an exception. Problem originates from a recent change: #2509300: Path alias UI allows node/1 and /node/1 as system path then fatals
Steps to reproduce:
- Add a new view (default settings)
- Add contextual filter 'Content: Node ID' - Settings:
- Default actions : Provide default value
- Type : Raw value from URL
- Use path alias : checked
- Click "Apply"
Results in the following:
Uncaught PHP Exception InvalidArgumentException: "Source path admin/structure/views/view/articles/preview/rest_export_1 has to start with a slash." at c:\...\www\...\core\lib\Drupal\Core\Path\AliasManager.php line 194
Saving the view while the filter is present will also produce the error.
Proposed resolution
Change trim()
to rtrim()
in Raw::getArgument (default argument plugin).
Will require some refactoring to keep the path component index syncing up with the proper arguments.
Add new test that checks for NULL or nonexistent path arguments.
Remaining tasks
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#26 | source_path_has_to-2569117-26.patch | 3.62 KB | cilefen |
#20 | interdiff.txt | 1 KB | othermachines |
#20 | drupal_core-2569117-18.patch | 3.6 KB | othermachines |
| |||
#17 | drupal_core-2569117-17-TEST-ONLY.patch | 2.55 KB | Lendude |
Comments
Comment #2
othermachines CreditAttribution: othermachines commentedComment #4
othermachines CreditAttribution: othermachines commentedI'm a creature of habit.
Comment #5
dawehnerThank for filing the issue and providing a fix!
That indeed totally makes sense, but we should better add some tests in order to ensure it doesn't happen in the future anymore.
We have a test in
core/modules/views/tests/src/Unit/Plugin/argument_default/RawTest.php
so we might could just expand that oneComment #9
othermachines CreditAttribution: othermachines commented@dawehner You're welcome. Was hoping it would be fast and easy but I'm a bit held up due to #2294731 Simpletest fails to run PHPUnit on Windows and in extracted tarballs of Drupal. Maybe need to resort to running from command line as you suggest but will need to install, etc. There are never enough hours in the day...
Comment #10
dawehnerWell, true. I think running the following on the command line should be enough:
Comment #11
othermachines CreditAttribution: othermachines commentedOr what you said, even. :)
For the record, I was able to run it successfully on Windows with:
-c
wasn't getting me anywhere. Should I be concerned about excluding it?Thanks for your help!
Comment #12
dawehnerOh well, the -c core is just needed in case you don't do the cd core before.
Comment #13
othermachines CreditAttribution: othermachines commentedAh sorry, that was confusing. I was just referring to the symlink not working in Windows (according to handbook page). But what
-c core
does now makes more sense. Thanks again.Comment #14
othermachines CreditAttribution: othermachines commentedFirst stab at a PHPUnit test. Let's hope this works. Thanks to @dawehner for helping me out here.
Revisions to
testGetArgument()
:getArgument()
for three path arguments -- [ ] / [ test ] / [ example ] -- instead of two. In the first instance 'use_alias' is FALSE (Use path alias is NOT selected).getAliasByPath()
as having a leading slash while expecting same as the return value.getArgument()
, but this time 'use_alias' is TRUE (Use path alias is selected).Comment #15
othermachines CreditAttribution: othermachines commentedYeah, no that's not gonna work. It occurred to me in the light of day that those URL indexes aren't just arbitrarily set for the purpose of testing. Back to it then...
Comment #16
othermachines CreditAttribution: othermachines commentedIgnore the last set of uploads. The diff is against the first patch.
New changes to
getArgument()
:array_shift()
to lop off the empty first element to ensure our function returns the same value as before based on path component index.Changes to
testGetArgument()
:getArgument()
when $options['index'] is NULL or path argument doesn't exist. In the first instance 'use_alias' is FALSE (Use path alias is NOT selected).getAliasByPath()
as having a leading slash while expecting same as the return value.I ran
testGetArgument()
with additions in #1 and #3 and no changes togetArgument()
to confirm the expected return values remain consistent:Comment #17
LendudeManually tested this. Could reproduce the issue with the steps described and the proposed patch solves the issue.
Always a good idea to have a failing test-only patch to highlight the problem, so I'll add that.
Couple of nitpicks:
Maybe also explain why not?
Maybe add a comment along the lines of what was said in #16.1?
Looks good otherwise.
Comment #20
othermachines CreditAttribution: othermachines commented@Lendude Thanks for the review and the test-only patch. (I've noticed the practice but I'm not clear on how it works.) Here's a revision based on your comments. Also updated issue with a couple more details.
Comment #21
othermachines CreditAttribution: othermachines commentedOops - broken link.
Comment #22
othermachines CreditAttribution: othermachines commentedgah - sorry. It's too early.
Comment #23
Lendude@othermachines you can link to other issues using square brackets, # and the issue number. Then you get the nice status colouring and strikethrough when fixed.
The test-only patches are for showing that it's an actual bug in HEAD. And then your combined test/fix patch show that you fixed the bug exposed by the test-only patch. Bit of reading on the how and why.
Patch looks go to me now.
Comment #24
othermachines CreditAttribution: othermachines commented@Lendude Really? So I don't have to type <a href> anymore? Thank god. In a perfect world there would only be markdown.
Thanks very much for the info!
Comment #26
cilefen CreditAttribution: cilefen commentedThis is a reroll.
Comment #27
othermachines CreditAttribution: othermachines commentedConfirming patch in #26 is good - no error, unit test passes.
Comment #28
LendudeStraight reroll so back to RTBC
Comment #29
dawehnerAn exception sounds like a potential RC target
Comment #30
xjmDiscussed with @effulgentsia. This is a pretty common usecase and it's basically completely broken, so tagging as an RC target.
Comment #32
catchCommitted/pushed to 8.0.x, thanks!