diff MoinMoin/wikiutil.py @ 2378:a7f4b02f5fdb

fix the quoting mess * double double-quotes (") to get a double quote inside quotes * quote things correctly when needed (not just "%s") * add and fix unit tests for this quoting * formatter must quote the name before it can pass it to resolve_wiki
author Johannes Berg <johannes AT sipsolutions DOT net>
date Sun, 15 Jul 2007 16:34:25 +0200
parents 629dea07759f
children b8b87daf7cc4
line wrap: on
line diff
--- a/MoinMoin/wikiutil.py	Sun Jul 15 14:05:12 2007 +0200
+++ b/MoinMoin/wikiutil.py	Sun Jul 15 16:34:25 2007 +0200
@@ -482,23 +482,19 @@
 
 # Quoting of wiki names, file names, etc. (in the wiki markup) -----------------------------------
 
+# don't ever change this
 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
+    return '"%s"' % name.replace('"', '""')
 
 def unquoteName(name):
     """ if there are quotes around the name, strip them """
     if not name:
         return name
-    for quote_char in QUOTE_CHARS:
-        if quote_char == name[0] == name[-1]:
-            return name[1:-1]
+    if '"' == name[0] == name[-1]:
+        return name[1:-1].replace('""', '"')
     else:
         return name
 
@@ -610,9 +606,21 @@
         except ValueError:
             wikiname, rest = 'Self', wikiurl
     if rest:
-        first_char = rest[0]
-        if first_char in QUOTE_CHARS: # quoted pagename
-            pagename_linktext = rest[1:].split(first_char, 1)
+        if rest[0] == '"': # quoted pagename
+            idx = 1
+            max = len(rest)
+            while idx < max:
+                if idx + 1 < max:
+                    next = rest[idx + 1]
+                else:
+                    next = None
+                if next == rest[idx] == '"':
+                    idx += 2
+                    continue
+                if next != '"' and rest[idx] == '"':
+                    break
+                idx += 1
+            pagename_linktext = rest[1:idx].replace('""', '"'), rest[idx+1:]
         else: # not quoted, split on whitespace
             pagename_linktext = rest.split(None, 1)
     else: