Skip to content

Commit f22e184

Browse files
committed
Fix clicking on revision in annotation mode returns 400
fixes #3689
1 parent b84dfa7 commit f22e184

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/GitRepository.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.IOException;
2929
import java.io.OutputStream;
3030
import java.nio.charset.StandardCharsets;
31+
import java.nio.file.Path;
3132
import java.nio.file.Paths;
3233
import java.util.Date;
3334
import java.util.HashSet;
@@ -324,14 +325,15 @@ public Annotation annotate(File file, String revision) throws IOException {
324325
if (revision == null) {
325326
revision = getFirstRevision(filePath);
326327
}
327-
Annotation annotation = getAnnotation(revision, filePath);
328+
String fileName = Path.of(filePath).getFileName().toString();
329+
Annotation annotation = getAnnotation(revision, filePath, fileName);
328330

329331
if (annotation.getRevisions().isEmpty() && isHandleRenamedFiles()) {
330332
// The file might have changed its location if it was renamed.
331333
// Try to lookup its original name and get the annotation again.
332334
String origName = findOriginalName(file.getCanonicalPath(), revision);
333335
if (origName != null) {
334-
annotation = getAnnotation(revision, origName);
336+
annotation = getAnnotation(revision, origName, fileName);
335337
}
336338
}
337339

@@ -361,8 +363,8 @@ private String getFirstRevision(String filePath) {
361363
}
362364

363365
@NotNull
364-
private Annotation getAnnotation(String revision, String filePath) throws IOException {
365-
Annotation annotation = new Annotation(filePath);
366+
private Annotation getAnnotation(String revision, String filePath, String fileName) throws IOException {
367+
Annotation annotation = new Annotation(fileName);
366368

367369
try (org.eclipse.jgit.lib.Repository repository = getJGitRepository(getDirectoryName())) {
368370
BlameCommand blameCommand = new Git(repository).blame().setFilePath(getGitFilePath(filePath));

opengrok-indexer/src/main/java/org/opengrok/indexer/web/Util.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.io.InputStream;
3535
import java.io.InputStreamReader;
3636
import java.io.Reader;
37-
import java.io.UnsupportedEncodingException;
3837
import java.io.Writer;
3938
import java.net.MalformedURLException;
4039
import java.net.URI;
@@ -913,15 +912,7 @@ public static void writeHAD(Writer out, String ctxE, String entry,
913912
* @see URLEncoder#encode(String, String)
914913
*/
915914
public static String URIEncode(String q) {
916-
try {
917-
return q == null ? "" : URLEncoder.encode(q,
918-
StandardCharsets.UTF_8.name());
919-
} catch (UnsupportedEncodingException e) {
920-
// Should not happen. UTF-8 must be supported by JVMs.
921-
LOGGER.log(
922-
Level.WARNING, "Failed to URL-encode UTF-8: ", e);
923-
}
924-
return null;
915+
return q == null ? "" : URLEncoder.encode(q, StandardCharsets.UTF_8);
925916
}
926917

927918
/**
@@ -1680,15 +1671,8 @@ public static Map<String, List<String>> getQueryParams(final URL url) {
16801671
continue;
16811672
}
16821673

1683-
String key = pair.substring(0, idx);
1684-
String value = pair.substring(idx + 1);
1685-
1686-
try {
1687-
key = URLDecoder.decode(key, StandardCharsets.UTF_8.toString());
1688-
value = URLDecoder.decode(value, StandardCharsets.UTF_8.toString());
1689-
} catch (UnsupportedEncodingException e) {
1690-
throw new IllegalStateException("Could not find UTF-8 encoding", e);
1691-
}
1674+
String key = URLDecoder.decode(pair.substring(0, idx), StandardCharsets.UTF_8);
1675+
String value = URLDecoder.decode(pair.substring(idx + 1), StandardCharsets.UTF_8);
16921676

16931677
List<String> paramValues = returnValue.computeIfAbsent(key, k -> new LinkedList<>());
16941678
paramValues.add(value);

0 commit comments

Comments
 (0)