Problem/Motivation
When adding a node or taxonomy term and the user enters only spaces in "Url Alias" path_form_element_validate executes unnecessary db_select query to check if the alias has been used. path_node_insert, path_node_update, path_taxonomy_term_insert, and path_taxonomy_term_update all trim the $path['alias'] before they check to see if it is empty therefore a spaces only alias will never be saved.
Proposed resolution
Trim the submitted URL alias before checking to see if it is empty. This will eliminate a potential unnecessary db_select execution.
Change
if (!empty($form_state['values']['path']['alias'])) {
// Trim the submitted value.
$alias = trim($form_state['values']['path']['alias']);
to
// Trim the submitted value.
$alias = trim($form_state['values']['path']['alias']);
if (!empty($alias)) {
I don't know if this is too much of an "corner case" to worry about.
The issue is the same in D7 and D8.
Patch forth coming....
Original report by tedbow
Comment | File | Size | Author |
---|---|---|---|
#7 | trim_alias_before_checking_empty-1393846-d7-7.patch | 871 bytes | Albert Volkman |
#1 | trim_alias_before_checking_empty-1393846-1.patch | 891 bytes | tedbow |
Comments
Comment #1
tedbowPatch attached
Comment #2
tamanna-freelancer CreditAttribution: tamanna-freelancer commentedI have reviewed this patch,it works fine.
Comment #3
tedbowGreat!
Comment #4
tedbowshoud this be backported to D7?
Comment #5
xjmYep. And I thought about it, and I don't think there's really a way nor a reason to test this. I also tested manually just to make sure we don't actually save a path of empty spaces.
(Cue either Floyd or Queen).
Comment #6
catchMakes sense, we can't test the presence of the extra query or not, so committed/pushed to 8.x.
Comment #7
Albert Volkman CreditAttribution: Albert Volkman commentedD7 backport.
Comment #8
xjmLooks fine for backport as well.
Comment #9
webchickNice catch! Committed and pushed to 7.x. Thanks!