changeset 1355:a796d366f176

wikiutil.(un)quoteName for (un)quoting names in wiki markup, fix quoting bug
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 20 Aug 2006 20:58:49 +0200
parents 26949e36ca0b
children 0120ccfbaaa1
files MoinMoin/parser/text_moin_wiki.py MoinMoin/wikiutil.py
diffstat 2 files changed, 24 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/parser/text_moin_wiki.py	Sun Aug 20 19:08:49 2006 +0200
+++ b/MoinMoin/parser/text_moin_wiki.py	Sun Aug 20 20:58:49 2006 +0200
@@ -372,7 +372,7 @@
         """
         word = text[1:-1] # strip brackets
         first_char = word[0]
-        if first_char in "'\"": # this is quoted
+        if first_char in wikiutil.QUOTE_CHARS:
             # split on closing quote
             target, linktext = word[1:].split(first_char, 1)
         else: # not quoted
@@ -394,7 +394,7 @@
             words = word[1:].split(':', 1)
             if len(words) == 1:
                 words = words * 2
-            target_and_text = 'wiki:Self:"%s" %s' % tuple(words)
+            target_and_text = 'wiki:Self:%s %s' % (wikiutil.quoteName(words[0]), words[1])
             return self.interwiki(target_and_text, pretty_url=1)
 
         scheme_and_rest = word.split(":", 1)
--- a/MoinMoin/wikiutil.py	Sun Aug 20 19:08:49 2006 +0200
+++ b/MoinMoin/wikiutil.py	Sun Aug 20 20:58:49 2006 +0200
@@ -490,6 +490,26 @@
             self.wlock.release()
 
 
+# Quoting of wiki names, file names, etc. (in the wiki markup) -----------------------------------
+
+QUOTE_CHARS = u"'\""
+
+def quoteName(name):
+    """ put quotes around a given name """
+    for quote_char in QUOTE_CHARS:
+        if quote_char not in name:
+            return u"%s%s%s" % (quote_char, name, quote_char)
+    else:
+        return name # XXX we need to be able to escape the quote char for worst case
+
+def unquoteName(name):
+    """ if there are quotes around the name, strip them """
+    for quote_char in QUOTE_CHARS:
+        if quote_char == name[0] == name[-1]:
+            return name[1:-1]
+    else:
+        return name
+
 #############################################################################
 ### InterWiki
 #############################################################################
@@ -594,7 +614,7 @@
         except ValueError:
             wikiname, rest = 'Self', wikiurl
     first_char = rest[0]
-    if first_char in "'\"": # quoted pagename
+    if first_char in QUOTE_CHARS: # quoted pagename
         pagename_linktext = rest[1:].split(first_char, 1)
     else: # not quoted, split on whitespace
         pagename_linktext = rest.split(None, 1)
@@ -822,7 +842,7 @@
     if re.match(Parser.word_rule + "$", pagename):
         return pagename
     else:
-        return u'["%s"]' % pagename
+        return u'["%s"]' % pagename # XXX use quoteName(pagename) later
 
 #############################################################################
 ### mimetype support
@@ -860,7 +880,6 @@
     MIMETYPES_spoil_mapping[value] = key
 
 
-# mimetype stuff ------------------------------------------------------------
 class MimeType(object):
     """ represents a mimetype like text/plain """