From a380ae69d5f84a50439d1612d3bfc946d8558ec5 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Wed, 15 May 2013 12:41:28 -0500 Subject: [PATCH] IS_SLUG patch, thanks Jonathan, Niphlod and Villas --- VERSION | 2 +- gluon/validators.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/VERSION b/VERSION index ac9168b6..6c7253d8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.4.6-stable+timestamp.2013.05.15.11.18.49 +Version 2.4.6-stable+timestamp.2013.05.15.12.39.42 diff --git a/gluon/validators.py b/gluon/validators.py index ff784d05..8fa964c3 100644 --- a/gluon/validators.py +++ b/gluon/validators.py @@ -2514,17 +2514,18 @@ class IS_UPPER(Validator): return (value.decode('utf8').upper().encode('utf8'), None) -def urlify(value, maxlen=80, keep_underscores=False): +def urlify(s, maxlen=80, keep_underscores=False): """ Convert incoming string to a simplified ASCII subset. if (keep_underscores): underscores are retained in the string else: underscores are translated to hyphens (default) """ - s = value.lower() # to lowercase - s = s.decode('utf-8') # to utf-8 + if isinstance(s, str): + s = s.decode('utf-8') # to unicode + s = s.lower() # to lowercase s = unicodedata.normalize('NFKD', s) # normalize eg è => e, ñ => n - s = s.encode('ASCII', 'ignore') # encode as ASCII - s = re.sub('&\w+;', '', s) # strip html entities + s = s.encode('ascii', 'ignore') # encode as ASCII + s = re.sub('&\w+?;', '', s) # strip html entities if keep_underscores: s = re.sub('\s+', '-', s) # whitespace to hyphens s = re.sub('[^\w\-]', '', s)