Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#317 closed defect (fixed)

[Patch] slugify delimits words by hyphens, but its validator doesn't like them

Reported by: hugo <gb@…> Owned by: Jacob
Component: Generic views Version: 0.95
Severity: normal Keywords: slugs slug slugify validation
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

. words separated by underscores ("_") or hyphens ("-") in URLs. Google will treat "keyword-phrase" as "keyword phrase" and "keyword_phrase" as "keywordphrase. - google handles _ and - differently, where the - form usually is what the user needs. So the slugify code should just handle multi-word sentences by delimiting the slugified words by hyphens.

Attachments (1)

slug.patch (2.5 KB) - added by sune.kirkeby@… 11 years ago.
Patch to change URLify.js, and add a separate validator for slugs.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 11 years ago by Manuzhai

I agree, and I have talked about this with jacobkm before. I also have patches, but they're kinda trivial. Just remember that you need to change both the validator and the prepopulating javascript.

Changed 11 years ago by sune.kirkeby@…

Attachment: slug.patch added

Patch to change URLify.js, and add a separate validator for slugs.

comment:2 Changed 11 years ago by sune.kirkeby@…

Summary: slugify should delimit words by hyphens[patch] slugify should delimit words by hyphens

Just added a patch which updates the prepopulating javascript to replace spaces with dashes, and add a separate validator (isSlug) for slugs, which accepts dashes in slugs.
Please, could this (or something like it) get committed? As the OP said, dashes and underscores are different in URLs, so they should both be allowed in slugs.

comment:3 Changed 11 years ago by garthk

Keywords: slugs slug slugify validation added
Summary: [patch] slugify should delimit words by hyphensslugify delimits words by hyphens, but its validator doesn't like them

I'm seeing dashes in my SlugFields after using django.core.defaultfilters.slugify in my _pre_save, but when I try to edit one of the postings afterward in the administration interface I get validation errors.

comment:4 Changed 11 years ago by Manuzhai

Summary: slugify delimits words by hyphens, but its validator doesn't like them[Patch] slugify delimits words by hyphens, but its validator doesn't like them

Hmm, isn't the regex just wrong?

Also, adding [Patch] to summary to gain inclusion in {12}.

comment:5 Changed 11 years ago by sune.kirkeby@…

Hmm, isn't the regex just wrong?

Which regex? I am running the patch I attached, and it works for me.

comment:6 Changed 11 years ago by Jacob

milestone: Version 1.0
Owner: changed from Adrian Holovaty to Jacob
Status: newassigned

comment:7 Changed 11 years ago by Adrian Holovaty

Resolution: fixed
Status: assignedclosed

(In [968]) Fixed #317 -- SlugField now accepts hyphens. Thanks, Sune

comment:8 Changed 11 years ago by hugo

Resolution: fixed
Status: closedreopened

urlify still delimits words by _ instead of -. I think we definitely should switch to delimiting by hyphens, as that's much more google friendly than underscores.

comment:9 Changed 11 years ago by Adrian Holovaty

Resolution: fixed
Status: reopenedclosed

This was fixed in [1017].

comment:10 Changed 10 years ago by (none)

milestone: Version 1.0

Milestone Version 1.0 deleted

comment:11 in reply to:  description Changed 10 years ago by anonymous

Component: Admin interfaceGeneric views
Has patch: set
Triage Stage: UnreviewedAccepted
Version: 0.95

Replying to hugo <gb@bofh.ms>:

. words separated by underscores ("_") or hyphens ("-") in URLs. Google will treat "keyword-phrase" as "keyword phrase" and "keyword_phrase" as "keywordphrase. - google handles _ and - differently, where the - form usually is what the user needs. So the slugify code should just handle multi-word sentences by delimiting the slugified words by hyphens.

Note: See TracTickets for help on using tickets.
Back to Top