From f5654729757eedefc1c656ac4be764b6a19ada2e Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 29 Mar 2013 10:59:26 -0400 Subject: [PATCH] Add more error checking to blob page --- releases.moxie | 1 + .../gitblit/wicket/GitBlitWebApp.properties | 3 ++- .../com/gitblit/wicket/pages/BlobPage.java | 23 +++++++++++++++++-- .../wicket/panels/CommitHeaderPanel.java | 1 + 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/releases.moxie b/releases.moxie index 8dac1dcb..05989142 100644 --- a/releases.moxie +++ b/releases.moxie @@ -9,6 +9,7 @@ r17: { - Raw servlet was insecure. If someone knew the exact repository name and path to a file, the raw blob could be retrieved bypassing security constraints. (issue 198) fixes: - Could not reset settings with $ or { characters through Gitblit Manager because they are not properly escaped + - Added more error checking to blob page - Fix NPE when getting user's fork without repository list caching (issue 182) - Fix internal error on folder history links (issue 192) - Fixed incorrect icon file name for .doc files (issue 200) diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties index 7a2b1bb3..b0d559f6 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties @@ -444,4 +444,5 @@ gb.excludeFromActivity = exclude from activity page gb.isSparkleshared = repository is Sparkleshared gb.owners = owners gb.sessionEnded = Session has been closed -gb.closeBrowser = Please close the browser to properly end the session. \ No newline at end of file +gb.closeBrowser = Please close the browser to properly end the session. +gb.doesNotExistInTree = {0} does not exist in tree {1} \ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/pages/BlobPage.java b/src/main/java/com/gitblit/wicket/pages/BlobPage.java index e2b8546b..ab0f0f16 100644 --- a/src/main/java/com/gitblit/wicket/pages/BlobPage.java +++ b/src/main/java/com/gitblit/wicket/pages/BlobPage.java @@ -124,20 +124,39 @@ public class BlobPage extends RepositoryPage { default: // plain text String source = JGitUtils.getStringContent(r, commit.getTree(), blobPath, encodings); - String table = generateSourceView(source, type == 1); + String table; + if (source == null) { + table = missingBlob(blobPath, commit); + } else { + table = generateSourceView(source, type == 1); + } add(new Label("blobText", table).setEscapeModelStrings(false)); add(new Image("blobImage").setVisible(false)); } } else { // plain text String source = JGitUtils.getStringContent(r, commit.getTree(), blobPath, encodings); - String table = generateSourceView(source, false); + String table; + if (source == null) { + table = missingBlob(blobPath, commit); + } else { + table = generateSourceView(source, false); + } add(new Label("blobText", table).setEscapeModelStrings(false)); add(new Image("blobImage").setVisible(false)); } } } + protected String missingBlob(String blobPath, RevCommit commit) { + StringBuilder sb = new StringBuilder(); + sb.append("
"); + String pattern = getString("gb.doesNotExistInTree").replace("{0}", "{0}").replace("{1}", "{1}"); + sb.append(MessageFormat.format(pattern, blobPath, commit.getTree().getId().getName())); + sb.append("
"); + return sb.toString(); + } + protected String generateSourceView(String source, boolean prettyPrint) { String [] lines = source.split("\n"); diff --git a/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java b/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java index bb960cca..eb757501 100644 --- a/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java @@ -33,6 +33,7 @@ public class CommitHeaderPanel extends BasePanel { add(new Label("commitid")); add(new Label("author")); add(new Label("date")); + add(new Label("authorAvatar")); } public CommitHeaderPanel(String id, String repositoryName, RevCommit c) { -- 2.39.5