Django

Code

Ticket #1849: collapse-hyphens.diff

File collapse-hyphens.diff, 1.2 kB (added by Tom Insam, 4 years ago)

patch

  • django/contrib/admin/media/js/urlify.js

    old new  
    1010    s = s.replace(/[^-A-Z0-9\s]/gi, '');  // remove unneeded chars 
    1111    s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces 
    1212    s = s.replace(/\s+/g, '-');      // convert spaces to hyphens 
     13    s = s.replace(/-+/g, '-');      // collapse repeated hyphens 
    1314    s = s.toLowerCase();             // convert to lowercase 
    1415    return s.substring(0, num_chars);// trim to first num_chars chars 
    1516} 
  • django/template/defaultfilters.py

    old new  
    6666def slugify(value): 
    6767    "Converts to lowercase, removes non-alpha chars and converts spaces to hyphens" 
    6868    value = re.sub('[^\w\s-]', '', value).strip().lower() 
    69     return re.sub('\s+', '-', value) 
     69    value = re.sub('\s+', '-', value) 
     70    return re.sub('-+', '-', value) 
    7071 
    7172def stringformat(value, arg): 
    7273    """