changeset 2568:80eac6fc152a

make anchor names always start with a letter
author Johannes Berg <johannes AT sipsolutions DOT net>
date Wed, 25 Jul 2007 15:52:28 +0200
parents b403a24f7c8f
children 5c9e46ab917c e76789b0e537
files MoinMoin/_tests/test_wikiutil.py MoinMoin/wikiutil.py
diffstat 2 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_wikiutil.py	Wed Jul 25 15:34:01 2007 +0200
+++ b/MoinMoin/_tests/test_wikiutil.py	Wed Jul 25 15:52:28 2007 +0200
@@ -721,8 +721,10 @@
     def test_anchor_name_encoding(self):
         tests = [
             # text                    expected output
-            (u'\xf6\xf6ll\xdf\xdf',   '.2BAPYA9g-ll.2BAN8A3w-'),
+            (u'\xf6\xf6ll\xdf\xdf',   'A.2BAPYA9g-ll.2BAN8A3w-'),
             (u'level 2',              'level_2'),
+            (u'',                     'A'),
+            (u'123',                  'A123'),
         ]
         for text, expected in tests:
             yield self._check, text, expected
--- a/MoinMoin/wikiutil.py	Wed Jul 25 15:34:01 2007 +0200
+++ b/MoinMoin/wikiutil.py	Wed Jul 25 15:52:28 2007 +0200
@@ -2101,7 +2101,10 @@
 
 def anchor_name_from_text(text):
     quoted = urllib.quote_plus(text.encode('utf-7'))
-    return quoted.replace('%', '.').replace('+', '_')
+    res = quoted.replace('%', '.').replace('+', '_')
+    if not res[:1].isalpha():
+        return 'A%s' % res
+    return res
 
 
 ########################################################################