From b554cb82fd6616521974dd8cf776a80981045360 Mon Sep 17 00:00:00 2001 From: KeyserSosa Date: Tue, 27 Jan 2009 11:20:33 -0800 Subject: [PATCH] small bugfixes; empty response no longer raises an exception; mangled thing_ids are ignored by vote; cnamed domains don't break when hitting /r/. --- r2/r2/controllers/reddit_base.py | 2 +- r2/r2/controllers/validator/validator.py | 7 +++++-- r2/r2/lib/utils/utils.py | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/r2/r2/controllers/reddit_base.py b/r2/r2/controllers/reddit_base.py index 332924aba..d2195a06f 100644 --- a/r2/r2/controllers/reddit_base.py +++ b/r2/r2/controllers/reddit_base.py @@ -532,7 +532,7 @@ class RedditController(BaseController): def post(self): response = c.response - content = response.content + content = filter(None, response.content) if isinstance(content, (list, tuple)): content = ''.join(content) for w in c.response_wrappers: diff --git a/r2/r2/controllers/validator/validator.py b/r2/r2/controllers/validator/validator.py index 9a3dc359b..5260d4583 100644 --- a/r2/r2/controllers/validator/validator.py +++ b/r2/r2/controllers/validator/validator.py @@ -265,7 +265,7 @@ def chksrname(x): class VLinkFullnames(Validator): - "A space- or comma-separated list of fullnames for Links" + "A space- or comma-separated list of fullnames for Links" valid_re = re.compile(r'^(' + Link._type_prefix + str(Link._type_id) + r'_[0-9a-z]+[ ,]?)+$') splitter = re.compile('[ ,]+') @@ -363,12 +363,15 @@ class VAccountByName(VRequired): return self.error() class VByName(VRequired): + fullname_re = re.compile(r'^' + Thing._type_prefix + + r'[0-9a-z]+_[0-9a-z]+$') + def __init__(self, param, error = errors.NO_THING_ID, *a, **kw): VRequired.__init__(self, param, error, *a, **kw) def run(self, fullname): - if fullname: + if fullname and self.fullname_re.match(fullname): try: return Thing._by_fullname(fullname, False, data=True) except NotFound: diff --git a/r2/r2/lib/utils/utils.py b/r2/r2/lib/utils/utils.py index 202728c5d..acd547321 100644 --- a/r2/r2/lib/utils/utils.py +++ b/r2/r2/lib/utils/utils.py @@ -1008,6 +1008,8 @@ def trace(fn): return new_fn def common_subdomain(domain1, domain2): + if not domain1 or not domain2: + return "" domain1 = domain1.split(":")[0] domain2 = domain2.split(":")[0] if len(domain1) > len(domain2):