From 2b6428a0e25e4ee54d213adc78d8c39077f1405d Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Wed, 29 Jun 2016 18:29:21 +0100 Subject: fix gitfile handler to work when # is URL-encoded For some reason, Chrome sometimes passes the URL with the # URL-encoded as %23. --- git_deps/handler.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'git_deps') 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") -- cgit