From 79f17dc1783175d967c5bebb16654f78ab1d84bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Mon, 17 Aug 2020 17:39:03 +0200 Subject: [PATCH] Don't 500 in blame.html on out-of-redis blobs Bad assumption on my part that blob.data would be a str because !blob.is_binary, somehow never came up in testing --- gitsrht/blueprints/repo.py | 8 +++++++- gitsrht/templates/blame.html | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index c5ed7bf..4c5be40 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -305,6 +305,12 @@ def blame(owner, repo, ref, path): return redirect(url_for("repo.log", owner=repo.owner.canonical_name, repo=repo.name, ref=ref, path="/".join(path))) + try: + data = blob.data.decode() + except: + return redirect(url_for("repo.log", + owner=repo.owner.canonical_name, repo=repo.name, ref=ref, + path="/".join(path))) try: blame = git_repo.blame("/".join(path), newest_commit=orig_commit.oid) @@ -315,7 +321,7 @@ def blame(owner, repo, ref, path): abort(400) return render_template("blame.html", view="blame", owner=owner, - repo=repo, ref=ref, path=path, entry=entry, blob=blob, + repo=repo, ref=ref, path=path, entry=entry, blob=blob, data=data, blame=blame, commit=orig_commit, highlight_file=_highlight_file, editorconfig=EditorConfig(git_repo, orig_commit.tree, path), lookup_user=lookup_user()) diff --git a/gitsrht/templates/blame.html b/gitsrht/templates/blame.html index ac6e781..6b2dcb9 100755 --- a/gitsrht/templates/blame.html +++ b/gitsrht/templates/blame.html @@ -106,7 +106,7 @@ pre, body { >{{loop.index}} {% endfor %} {{ highlight_file(repo, ref, entry.name, - blob.data, blob.id.hex, commit.id.hex) }} + data, blob.id.hex, commit.id.hex) }} -- 2.38.4