Commits

Yuya Nishihara  committed 820aa60

serve: minimal support for paths containing space or comma (fixes #2082)

Since hg 8cbb59124e67, each entry of paths is parsed as a list.

Because we don't have ui.configlist()-compatible function, ServeDialog and
WebconfForm cannot parse value as a list. So for now, it only quotes paths
in multi-repository (i.e. --web-conf) mode.

  • Participants
  • Parent commits dffcdcc
  • Branches stable

Comments (0)

Files changed (1)

File tortoisehg/hgqt/serve.py

     except (EnvironmentError, error.Abort, error.RepoError):
         pass
 
+def _asconfigliststr(value):
+    r"""
+    >>> _asconfigliststr('foo')
+    'foo'
+    >>> _asconfigliststr('foo bar')
+    '"foo bar"'
+    >>> _asconfigliststr('foo,bar')
+    '"foo,bar"'
+    >>> _asconfigliststr('foo "bar"')
+    '"foo \\"bar\\""'
+    """
+    # ui.configlist() uses isspace(), which is locale-dependent
+    if util.any(c.isspace() or c == ',' for c in value):
+        return '"' + value.replace('"', '\\"') + '"'
+    else:
+        return value
+
 def _newwebconf(repopath, webconfpath):
     """create config obj for hgweb"""
     if webconfpath:
             repo = thgrepo.repository(None, repopath)
             roots = [root for root in recursiveRepoSearch(repo)]
             if len(roots) == 1:
+                # no _asconfigliststr(repopath) for now, because ServeDialog
+                # cannot parse it as a list in single-repo mode.
                 c.set('paths', '/', repopath)
             else:
+                # since hg 8cbb59124e67, path entry is parsed as a list
                 base = hglib.fromunicode(repo.shortname)
-                c.set('paths', base, repopath)
+                c.set('paths', base, _asconfigliststr(repopath))
                 for root in roots[1:]:
-                    c.set('paths', base + root[len(repopath):], root)
+                    c.set('paths', base + root[len(repopath):],
+                          _asconfigliststr(root))
         except (EnvironmentError, error.Abort, error.RepoError):
             c.set('paths', '/', repopath)
         return c