aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Spiers <git@adamspiers.org>2016-06-29 18:29:21 +0100
committerAdam Spiers <git@adamspiers.org>2018-05-15 13:42:16 +0100
commit2b6428a0e25e4ee54d213adc78d8c39077f1405d (patch)
treeb66a6f9c4f06562f0fdcfaf2ce147fedd9fe46c4
parentae29575ff9e22d088dd2f974a9de2c040d34c60f (diff)
downloadgit-deps-2b6428a0e25e4ee54d213adc78d8c39077f1405d.tar.gz
fix gitfile handler to work when # is URL-encoded
For some reason, Chrome sometimes passes the URL with the # URL-encoded as %23.
-rwxr-xr-xgit_deps/handler.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/git_deps/handler.py b/git_deps/handler.py
index 2fa2c54..572ed84 100755
--- a/git_deps/handler.py
+++ b/git_deps/handler.py
@@ -2,9 +2,13 @@
from __future__ import print_function
+import logging
+import logging.handlers
import os
+import re
import subprocess
import sys
+import urllib
from urlparse import urlparse
from git_deps.utils import abort
@@ -14,11 +18,34 @@ def usage():
abort("usage: git-handler URL")
+def get_logger():
+ logger = logging.getLogger('foo')
+ # logger.setLevel(logging.DEBUG)
+
+ slh = logging.handlers.SysLogHandler(address='/dev/log')
+ slf = logging.Formatter('gitfile-handler: %(message)s')
+ slh.setFormatter(slf)
+ logger.addHandler(slh)
+ logger.addHandler(logging.StreamHandler())
+
+ return logger
+
+
def main(args):
if len(args) != 1:
usage()
+ logger = get_logger()
+
url = args[0]
+ logger.debug("received URL: %s" % url)
+ if re.search(r'%23', url):
+ # Uh-oh, double-encoded URIs! Some versions of Chrome
+ # encode the value you set location.href too.
+ url = urllib.unquote(url)
+ logger.debug("unquoted: %s" % url)
+ url = urlparse(url)
+ logger.debug("parsed: %r" % repr(url))
if url.scheme != 'gitfile':
abort("URL must use gitfile:// scheme")