croogo / croogo

A CakePHP powered Content Management System
http://www.croogo.org
Other
817 stars 309 forks source link

Add validation rules for slugs #286

Open ghost opened 10 years ago

ghost commented 10 years ago

Created by Pierre Martin, 23rd Jan 2013. (originally Lighthouse ticket #342):


So far slugs are not validated server side, so it is possible to save slugs like "my-awesome-page&more" which is incorrect.

This ticket is about adding a validation rule for slugs. I suggest something very simple like :

   'rule' => '/^[-a-z0-9]+$/i',
   'message' => __('The slug can only contain alphanumeric characters and hyphens.', true)

... or using a more complete regex similar to what is used in the "url" validation rule

ghost commented 10 years ago

7th Feb 2013, Pierre Martin said:


Note: we detected an issue with the previous regex for Attachments slugs. Since their slug seems to be used for filenames it needs at least to allow ".", and maybe more. Further investigation is needed.

ghost commented 10 years ago

10th Feb 2013, Grégory Salvan said:


hi, django framework implements slugs with the rule you've given. I think it's good to keep this rule for slugs.

Why not implementing another rule with the POSIX "fully portable filenames" : "/[-._a-z0-9]+$/i" for attachment slugs ?

ghost commented 10 years ago

10th Feb 2013, Grégory Salvan said:


oups sorry django and rails manages underscores in slugs.

django: https://docs.djangoproject.com/en/dev/ref/models/fields/#slugfield

rails: https://github.com/ludo/to_slug

subodhghulaxe commented 10 years ago

WordPress function "sanitize_title_with_dashes" may be helpful http://wpseek.com/sanitize_title_with_dashes/