Code

Opened 7 years ago

Closed 7 years ago

#5368 closed (wontfix)

allow .(dot) in slug fields

Reported by: Amit Upadhyay <upadhyay@…> Owned by: amitu
Component: Uncategorized Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Slug fields are used for url construction, and in cases when someone is switching their website to django they may want to preserve the old urls. I have done so on my blog, which was hosted blogger blog, and all urls ended with .html. Django admin does not allow me to edit the posts as slug fields do not allow dot. It should be allowed.

Attachments (2)

allow-dot.patch (168.2 KB) - added by Amit Upadhyay <upadhyay@…> 7 years ago.
fix and documentation update.
allow_dot.patch (1.1 KB) - added by amitu 7 years ago.

Download all attachments as: .zip

Change History (11)

Changed 7 years ago by Amit Upadhyay <upadhyay@…>

fix and documentation update.

comment:1 follow-up: Changed 7 years ago by Yuri Baburov <burchik@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

If one don't use generic views, he can simply add "(?P<slug>\w+).html" in your urls.
And could you please correct end of line differences in your patch...

Changed 7 years ago by amitu

comment:2 Changed 7 years ago by amitu

  • Owner changed from nobody to amitu
  • Status changed from new to assigned

comment:3 Changed 7 years ago by amitu

  • Has patch set

comment:4 in reply to: ↑ 1 ; follow-up: Changed 7 years ago by amitu

Replying to Yuri Baburov <burchik@gmail.com>:

If one don't use generic views, he can simply add "(?P<slug>\w+).html" in your urls.
And could you please correct end of line differences in your patch...

My automated import script ended up dumping data in SlugField without verification, along with ".html" in it. So it is mostly my problem and django need not necessarily be changed.

Just wondering, why is dot not allowed in slug? Its a very mainstream character in URLs.

I am +0 on this fix.

comment:5 in reply to: ↑ 4 ; follow-up: Changed 7 years ago by Yuri Baburov <burchik@…>

Just wondering, why is dot not allowed in slug? Its a very mainstream character in URLs.

And why they should be allowed? :)

I am +0 on this fix.

Imagine you have web 2.0 tag and site did slug "web-2.0" and you have got url "/tags/web2.0/blablabla" instead of "/tags/web20/". That's fine.
But did you think about backward compatibility?
Lots of people will be required to change their slug regexps in URLconf... Including me! :(
So I am -1...

comment:6 Changed 7 years ago by Simon G. <dev@…>

  • Triage Stage changed from Unreviewed to Design decision needed

comment:7 in reply to: ↑ 5 ; follow-up: Changed 7 years ago by anonymous

Replying to Yuri Baburov <burchik@gmail.com>:

Just wondering, why is dot not allowed in slug? Its a very mainstream character in URLs.

And why they should be allowed? :)

Taking your example of tags, slug is the proper choice for the text of the tag, but people want to use .(dot) in their tag names, to not allow it on legacy/backward compatibility is just a technology quirk we are allowing to dictate a decision. Sure technological considerations are important and there is a work around, monkey patch or use your own SlugField derived class, but for the simple use case of using slug as tag, the fact that .(dot) was not allowed would be seen as a historic mistake and not as a decision taken on strong technical grounds.

But why stop at .(dot), how about the other characters? The basic idea behind slug comes from beautiful URLs, and "~ ` !@#$%&*()-_=+:;'",.?" gets translated to "%7E+%60+%21%40%23%24%25%5E%26*%28%29-_%3D%2B%3A%3B%27%22%2C.%3F" in URL, and we can see that only *(asterisk), -(hyphen), _(underscore) and .(dot) do not get mangled. We do not allow _(underline) because links are usually underlined, and its difficult to see the underline in links. This leaves us with precisely two characters: dot and hyphen (1), one is already allowed(hyphen) and I feel we should allow the other one too.

1: *(asterisk) is a mathematical symbol that people do not usually use so it may be left out, but with this line of reasoning it may be okay to allow it too.

comment:8 in reply to: ↑ 7 Changed 7 years ago by Yuri Baburov <burchik@…>

Replying to anonymous:

1: *(asterisk) is a mathematical symbol that people do not usually use so it may be left out, but with this line of reasoning it may be okay to allow it too.

Asterisk is also used in filesystems and may confuse site users.
Dots are used for file extensions.
Wouldn't it be strange if dots will appear in slugs when not expected?
I'm changing my mind to +0.

comment:9 Changed 7 years ago by mtredinnick

  • Resolution set to wontfix
  • Status changed from assigned to closed

I think this is all a bit of a non-issue. Slug fields are for a particular style of string. Underneath, though, they are just character fields with a validator. So if you want different validation requirements, just use a CharField and your own validator.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.