From 71df1b0a3178f3f4801430eff0741cc4391b73ce Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Fri, 7 Jun 2019 14:17:33 +0100 Subject: [PATCH] Encode file path when building url, allows unicode --- .../ic/wlgitbridge/data/CandidateSnapshot.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/data/CandidateSnapshot.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/data/CandidateSnapshot.java index f27601227b..29aa917011 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/data/CandidateSnapshot.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/data/CandidateSnapshot.java @@ -5,10 +5,13 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import uk.ac.ic.wlgitbridge.data.filestore.RawFile; import uk.ac.ic.wlgitbridge.data.filestore.RawDirectory; +import uk.ac.ic.wlgitbridge.util.Log; import uk.ac.ic.wlgitbridge.util.Util; import java.io.File; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -115,10 +118,17 @@ public class CandidateSnapshot implements AutoCloseable { JsonObject jsonFile = new JsonObject(); jsonFile.addProperty("name", file.getPath()); if (file.isChanged()) { - jsonFile.addProperty( - "url", - projectURL + "/" + file.getPath() + "?key=" + postbackKey - ); + String path = file.getPath(); + String encodedPath; + try { + encodedPath = URLEncoder.encode(path, "UTF-8"); + } catch (UnsupportedEncodingException e) { + // This should never happen + Log.error("Error while encoding file path: projectUrl={}, path={}", projectURL, path, e); + encodedPath = path; + } + String url = projectURL + "/" + encodedPath + "?key=" + postbackKey; + jsonFile.addProperty("url", url); } return jsonFile; }