Use a case-sensitive version of SafeConfigParser everywhere
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Mon, 16 Oct 2006 15:38:53 -0300
changeset 3425 ec6f400cff4d
parent 3424 9b1c126b74cd
child 3426 bb00a5a92c30
Use a case-sensitive version of SafeConfigParser everywhere This change has the potential to break existing setups, but the current behaviour (the keys in configuration files are always lower-cased) can bite us in a few places: - no way to use a Command in [defaults] - hgext.Extension doesn't work in [extensions] - you can't use an Upper/case/PATH in the [paths] section of hgweb.config - you can't (easily) protect paths with upper-case letters with the acl extension - you can't specify a /Path/TO/a/rEPO in the [reposubs] section for the notify extension
mercurial/hgweb/hgwebdir_mod.py
mercurial/ui.py
mercurial/util.py
tests/test-config-case
tests/test-config-case.out
--- a/mercurial/hgweb/hgwebdir_mod.py	Mon Oct 16 11:36:57 2006 -0700
+++ b/mercurial/hgweb/hgwebdir_mod.py	Mon Oct 16 15:38:53 2006 -0300
@@ -8,7 +8,7 @@
 
 import os
 from mercurial.demandload import demandload
-demandload(globals(), "ConfigParser mimetools cStringIO")
+demandload(globals(), "mimetools cStringIO")
 demandload(globals(), "mercurial:ui,hg,util,templater")
 demandload(globals(), "mercurial.hgweb.hgweb_mod:hgweb")
 demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile,style_map")
@@ -30,7 +30,7 @@
             self.repos = cleannames(config.items())
             self.repos.sort()
         else:
-            cp = ConfigParser.SafeConfigParser()
+            cp = util.configparser()
             cp.read(config)
             self.repos = []
             if cp.has_section('web'):
--- a/mercurial/ui.py	Mon Oct 16 11:36:57 2006 -0700
+++ b/mercurial/ui.py	Mon Oct 16 15:38:53 2006 -0300
@@ -11,7 +11,7 @@
 demandload(globals(), "ConfigParser traceback util")
 
 def dupconfig(orig):
-    new = ConfigParser.SafeConfigParser(orig.defaults())
+    new = util.configparser(orig.defaults())
     updateconfig(orig, new)
     return new
 
@@ -37,7 +37,7 @@
             self.debugflag = debug
             self.interactive = interactive
             self.traceback = traceback
-            self.cdata = ConfigParser.SafeConfigParser()
+            self.cdata = util.configparser()
             self.readconfig(util.rcpath())
             self.updateopts(verbose, debug, quiet, interactive)
         else:
@@ -126,7 +126,7 @@
 
     def setconfig(self, section, name, value):
         if not self.overlay:
-            self.overlay = ConfigParser.SafeConfigParser()
+            self.overlay = util.configparser()
         for cdata in (self.overlay, self.cdata):
             if not cdata.has_section(section):
                 cdata.add_section(section)
--- a/mercurial/util.py	Mon Oct 16 11:36:57 2006 -0700
+++ b/mercurial/util.py	Mon Oct 16 15:38:53 2006 -0300
@@ -15,7 +15,7 @@
 from i18n import gettext as _
 from demandload import *
 demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile")
-demandload(globals(), "os threading time calendar")
+demandload(globals(), "os threading time calendar ConfigParser")
 
 # used by parsedate
 defaultdateformats = ('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M',
@@ -24,6 +24,11 @@
 class SignalInterrupt(Exception):
     """Exception raised on SIGTERM and SIGHUP."""
 
+# like SafeConfigParser but with case-sensitive keys
+class configparser(ConfigParser.SafeConfigParser):
+    def optionxform(self, optionstr):
+        return optionstr
+
 def cachefunc(func):
     '''cache the result of function calls'''
     # XXX doesn't handle keywords args
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-config-case	Mon Oct 16 15:38:53 2006 -0300
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+echo '[Section]' >> $HGRCPATH
+echo 'KeY = Case Sensitive' >> $HGRCPATH
+echo 'key = lower case' >> $HGRCPATH
+
+hg showconfig
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-config-case.out	Mon Oct 16 15:38:53 2006 -0300
@@ -0,0 +1,2 @@
+Section.KeY=Case Sensitive
+Section.key=lower case