Problem/Motivation
The path alias field description says, "Use a relative path without a trailing slash" because doing the contrary of either of those things will result in a non-functional alias, but the field validation doesn't check for them.
Proposed resolution
We should check for them. :) Obviously we know they're problems. We may as well prevent them!
(Follow-up to address the duplication that was already in the code before this issue here: #2203573: Path alias validation and tests duplicative, inconsistent.)
Remaining tasks
- Needs committer review.
User interface changes
None.
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#48 | interdiff.txt | 2.08 KB | TravisCarden |
#48 | path_alias_validation-1847174-48.patch | 6.3 KB | TravisCarden |
#42 | path_alias_validation-1847174-42-tests.patch | 2.9 KB | TravisCarden |
Comments
Comment #1
TravisCarden CreditAttribution: TravisCarden commentedComment #2
iaine CreditAttribution: iaine commentedI could not get the error messages to appear until I moved the patch in the path.admin.inc file. After that the error messages showed correctly in the UI.
Comment #4
TravisCarden CreditAttribution: TravisCarden commentedIf you move the code there it won't validate taxonomy term aliases. I think my patch was actually correct. All you have to do to test it is to try to create a node or taxonomy term with a path alias that begins or ends with a forward slash (/). Here's the patch again with tests.
Comment #5
iaine CreditAttribution: iaine commentedI see what you are getting at with the taxonomy which your patch fixes and mine missed. However setting the admin form for a url alias allows both leading and trailing slashes as that form appears to run through the path_admin_form functions. I've rerolled with both sets of patches and this outputs the error messages to the UI for the user in both cases.
Comment #7
TravisCarden CreditAttribution: TravisCarden commentedOhhh. I was using the node edit form, and you were using the Path admin form, and they don't use the same validation routine. Well, that's ugly. There's duplication (and variation) of logic, different error messages for the same things, and inconsistent test coverage. I don't know if we should resolve the duplication here or file another issue for it. Why don't we get a working patch so we can get a core developer's attention on it and they can make a recommendation. Attached.
@iaine, I'm not certain why your patches are failing, but I notice they contain tabs and trailing spaces. See our Coding standards for information on how we handle indentation and whitespace. In general, if you see red highlighting in
git diff
or Dreditor, there's a problem. Also, you can run the automated tests yourself on your local installation using the Testing module so you know the outcome before uploading.Comment #8
TravisCarden CreditAttribution: TravisCarden commentedRerolling #7. Failing -tests.patch still applies.
Comment #10
TravisCarden CreditAttribution: TravisCarden commentedComment #11
TravisCarden CreditAttribution: TravisCarden commentedOh; API changes. Let's try this again.
Note: Added #2203573: Path alias validation and tests duplicative, inconsistent as follow-up to fix API inconsistency.
Comment #13
Mariano CreditAttribution: Mariano commentedHey all, following the issue here. I've added some testing for the admin form in addition to the current submitted testing improvements.
Comment #16
TravisCarden CreditAttribution: TravisCarden commentedPerfect, @Mariano; thanks! That completes test coverage. I think this is ready for committer review now. For their sake, I'm going to attach a tests patch that includes all the tests added in the complete patch so they can see them fail together and review them at once. And to keep the testbot happy, I'm going to re-attach your complete patch as well. If it passes (as it should), I think we can RTBC this.
Comment #18
TravisCarden CreditAttribution: TravisCarden commentedThere we go!
Comment #19
TravisCarden CreditAttribution: TravisCarden commentedComment #20
webchickWe're trying not to introduce anymore calls to derepcated procedural wrappers; this should be changed to Unicode::substr(), \Drupal::formBuilder()>setError()/getError().
Comment #21
TravisCarden CreditAttribution: TravisCarden commentedWe can fix that. Thanks, @webchick! (Tests-only patch is unchanged.)
Comment #22
Mariano CreditAttribution: Mariano commentedLooks good!
Comment #24
TravisCarden CreditAttribution: TravisCarden commented21: path-alias-validation-1847174-21-complete.patch queued for re-testing.
Comment #25
TravisCarden CreditAttribution: TravisCarden commentedI take it there was a regression in HEAD. This patch never changed, obviously, and it passes again.
Comment #26
webchickI don't mind committing this, since it's test coverage of an existing code path that previously lacked it, and that's +++.
However, from a usability POV, it would be *way* nicer if Drupal would just strip the trailing slash for you if you happened to provide it. It's like forms that ask you for a phone number and then yell at you when you have "-" in them. I could remove it, but a computer could also remove it just as easily.
Is there a reason not to just do that here, for better UX?
Comment #27
antonioG4 CreditAttribution: antonioG4 commentedI'm going to take a stab at rerolling this since the directory structured changed. But also, I'm agreeing with @webchick, that it is annoying to have to reenter something that the validation could also fix, and this is a pretty simplistic replacing of unnecessary "/"
Comment #28
Jody LynnI redid the patch to trim leading and trailing slashed in aliases, to test that they are removed, and to reduce the complexity of the help text.
Comment #30
Jody LynnComment #31
Jody LynnComment #32
Jody LynnComment #37
droplet CreditAttribution: droplet commentedIt should trims both "\" & "/"
Comment #38
boromino CreditAttribution: boromino commentedFixed function name and array index.
Comment #39
boromino CreditAttribution: boromino commentedComment #40
boromino CreditAttribution: boromino commentedComment #41
znerol CreditAttribution: znerol commentedIt is weird that in one place the description is about data and in the other it is about content (I realize that this is nothing new, but still might be worth unifying on this occasion). Also would it be possible to use exact the same sentence (less work for translators)?
One thing which is also not clear from the description is that its possible to use slashes in order to build up content hierarchies (reflected in breadcrumbs).
Comment #42
TravisCarden CreditAttribution: TravisCarden commentedA couple of small issues:
trim()
can do the whole job in a single invocation. This trims all whitespace characters and both kinds of slashes.$alias = trim($alias, " \t\n\r\0\x0B\\/");
Attached is an updated patch that addresses these things and @droplet's comment in #37. I don't happen to have a working installation of D8 at my disposal at the moment, so I can't test (and thus can't RTBC). Hopefully I didn't break it. :)
Comment #43
TravisCarden CreditAttribution: TravisCarden commentedOops. I didn't get the whole interdiff. Here's the full one.
Comment #45
znerol CreditAttribution: znerol commented@TravisCarden: Do you think it is worth addressing #41 or are there any reasons against?
Comment #46
TravisCarden CreditAttribution: TravisCarden commentedMy personal feeling is that the two contexts are different enough that it's actually appropriate to have the messages different. You'll notice that they're even written in difference voices. (One is in the imperative mood. The other one isn't technically even a sentence at the beginning--it's a subject clause with a period on the end.) That's not to say that I necessarily like them, but I wouldn't hold up this issue on improving them.
If someone wanted to enhance the "about" alias examples to imply directory depth, I would support that.
Comment #47
znerol CreditAttribution: znerol commentedI feel this is much less readable than
trim(trim($alias), " \\/");
. Other than that the patch is ready.I leave it to the person working on the patch and the committer on whether or not #41 should be addressed.
Comment #48
TravisCarden CreditAttribution: TravisCarden commented@znerol: If a literal space is the only whitespace character we want to support on the inside of a slash, then the two are functionally equivalent, and yours is indeed more readable. If we want to strip other whitespace characters (like vertical tab or newline) inside slashes, they are different:
" / alias/with/slashes-and-whitespace / "
trim($alias, " \t\n\r\0\x0B\\/")
"alias/with/slashes-and-whitespace"
trim(trim($alias), " \\/")
" alias/with/slashes-and-whitespace "
That contingency seems like an edge case, though--perhaps one that shouldn't be supported. Attached is a patch implementing your suggestion, @znerol. The tests-only patch in #42 remains valid.
Comment #49
znerol CreditAttribution: znerol commented@TravisCarden: I did not realize this ramifications.
Note to committers: This was RTBC twice before (see #20 and #26). All of the concerns expressed there have been addressed.
There was a short discussion starting at #41 on whether or not to reword the description. #47 and #48 are about whether to use one
trim
or two of them (this is a question about readability vs catching edge cases).Regardless I think this is ready.
Comment #50
tstoecklerThis is probably not a problem, because linking to such things does not really make sense, but wanted to note that this will disallow linking to relative URIs such as
//example.com/foo.js
.Comment #51
alexpottThis issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 79d21e7 and pushed to 8.0.x. Thanks!
Comment #54
osopolarFollow-Up to backport to Drupal 7: #2962374: [D7] Path alias validation should test for relative path, no trailing slash requirements