From afbbe11be06698ef9a00b4cd380711255328c9d2 Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Mon, 25 Aug 2025 17:08:27 +0200 Subject: [PATCH 1/9] fix nits and javadoc --- .../java/org/opengrok/indexer/web/Util.java | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/web/Util.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/web/Util.java index 3f5be5a8dd7..14c677a3654 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/web/Util.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/web/Util.java @@ -660,7 +660,7 @@ public static void encode(String s, Appendable dest) throws IOException { char c = s.charAt(i); if (c > 127 || c == '"' || c == '<' || c == '>' || c == '&' || c == '\'') { // special html characters - dest.append("&#").append("" + (int) c).append(";"); + dest.append("&#").append(Integer.toString(c)).append(";"); } else if (c == ' ') { // non-breaking space dest.append(" "); @@ -917,24 +917,22 @@ public static void writeHAD(Writer out, String ctxE, String entry) throws IOExce /** * Wrapper around UTF-8 URL encoding of a string. * - * @param q query to be encoded. If {@code null}, an empty string will be used instead. - * @return null if failed, otherwise the encoded string + * @param string to be encoded. If {@code null}, an empty string will be used instead. + * @return {@code null} if failed, otherwise the encoded string * @see URLEncoder#encode(String, String) */ - public static String uriEncode(String q) { - return q == null ? "" : URLEncoder.encode(q, StandardCharsets.UTF_8); + public static String uriEncode(String string) { + return string == null ? "" : URLEncoder.encode(string, StandardCharsets.UTF_8); } /** - * Append to {@code dest} the UTF-8 URL-encoded representation of - * {@code str}. + * Append to {@code dest} the UTF-8 URL-encoded representation of {@code str}. * @param str a defined instance * @param dest a defined target * @throws IOException I/O */ public static void uriEncode(String str, Appendable dest) throws IOException { - String uenc = uriEncode(str); - dest.append(uenc); + dest.append(uriEncode(str)); } /** @@ -948,7 +946,6 @@ public static void uriEncode(String str, Appendable dest) throws IOException { * @see #uriEncode(String) */ public static void appendQuery(StringBuilder buf, String key, String value) { - if (value != null) { buf.append(AMP).append(key).append('=').append(uriEncode(value)); } @@ -1647,15 +1644,13 @@ public static String linkifyPattern(String text, Pattern pattern, String url) { /** * Try to complete the given URL part into full URL with server name, port, scheme, ... *
- *
for request http://localhost:8080/source/xref/xxx and part - * /cgi-bin/user=
- *
http://localhost:8080/cgi-bin/user=
- *
for request http://localhost:8080/source/xref/xxx and part - * cgi-bin/user=
- *
http://localhost:8080/source/xref/xxx/cgi-bin/user=
- *
for request http://localhost:8080/source/xref/xxx and part - * http://users.com/user=
- *
http://users.com/user=
+ *
for request {@code http://localhost:8080/source/xref/xxx} and part {@code /cgi-bin/user=}
+ *
{@code http://localhost:8080/cgi-bin/user=}
+ *
for request {@code http://localhost:8080/source/xref/xxx} and part {@code cgi-bin/user=}
+ *
{@code http://localhost:8080/source/xref/xxx/cgi-bin/user=}
+ *
for request {@code http://localhost:8080/source/xref/xxx} and part + * {@code http://users.com/user=}
+ *
{@code http://users.com/user=}
*
* * @param url the given URL part, may be already full URL From c0877281cb4be338f3ba8154ad23efb9ea41eba3 Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Mon, 25 Aug 2025 17:08:35 +0200 Subject: [PATCH 2/9] encode the link as URI --- opengrok-web/src/main/webapp/rss.jsp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opengrok-web/src/main/webapp/rss.jsp b/opengrok-web/src/main/webapp/rss.jsp index 41ac6135453..ed5f6fc327b 100644 --- a/opengrok-web/src/main/webapp/rss.jsp +++ b/opengrok-web/src/main/webapp/rss.jsp @@ -97,8 +97,8 @@ org.opengrok.web.PageConfig" } requestURL += request.getContextPath(); - requestURL += Prefix.HIST_L + cfg.getPath() + "#" + entry.getRevision(); - %><%= Util.htmlize(requestURL) %> + requestURL += Prefix.HIST_L + Util.uriEncodePath(cfg.getPath()) + "#" + Util.uriEncode(entry.getRevision()); + %><%= requestURL %> <% for (String e : entry.getMessage().split("\n")) { %> From 5565ec63dc36d211cd4c5c3d4bffc68952ee47c2 Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Mon, 25 Aug 2025 17:09:44 +0200 Subject: [PATCH 3/9] rename for better readability --- opengrok-web/src/main/webapp/rss.jsp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/opengrok-web/src/main/webapp/rss.jsp b/opengrok-web/src/main/webapp/rss.jsp index ed5f6fc327b..a48e1152966 100644 --- a/opengrok-web/src/main/webapp/rss.jsp +++ b/opengrok-web/src/main/webapp/rss.jsp @@ -40,10 +40,10 @@ org.opengrok.web.PageConfig" PageConfig cfg = PageConfig.get(request); cfg.checkSourceRootExistence(); - String redir = cfg.canProcess(); - if (redir == null || !redir.isEmpty()) { - if (redir != null) { - response.sendRedirect(redir); + String redirectLocation = cfg.canProcess(); + if (redirectLocation == null || !redirectLocation.isEmpty()) { + if (redirectLocation != null) { + response.sendRedirect(redirectLocation); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } From 30ab634b6a5cca98676feca34e44e653a86e167a Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Mon, 25 Aug 2025 17:13:01 +0200 Subject: [PATCH 4/9] simplify description --- opengrok-web/src/main/java/org/opengrok/web/PageConfig.java | 2 ++ opengrok-web/src/main/webapp/rss.jsp | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/opengrok-web/src/main/java/org/opengrok/web/PageConfig.java b/opengrok-web/src/main/java/org/opengrok/web/PageConfig.java index f06e7107f17..6d0c0439ed3 100644 --- a/opengrok-web/src/main/java/org/opengrok/web/PageConfig.java +++ b/opengrok-web/src/main/java/org/opengrok/web/PageConfig.java @@ -66,6 +66,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.ws.rs.core.HttpHeaders; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.VisibleForTesting; import org.opengrok.indexer.Info; @@ -691,6 +692,7 @@ public EftarFileReader getEftarReader() { * * @return an empty string if not found, the tag otherwise. */ + @NotNull public String getDefineTagsIndex() { if (dtag != null) { return dtag; diff --git a/opengrok-web/src/main/webapp/rss.jsp b/opengrok-web/src/main/webapp/rss.jsp index a48e1152966..833acf5c3fd 100644 --- a/opengrok-web/src/main/webapp/rss.jsp +++ b/opengrok-web/src/main/webapp/rss.jsp @@ -50,7 +50,6 @@ org.opengrok.web.PageConfig" return; } String path = cfg.getPath(); - String dtag = cfg.getDefineTagsIndex(); response.setContentType("text/xml"); %> Changes in <%= path.isEmpty() ? "Cross Reference" : Util.htmlize(cfg.getResourceFile().getName()) %> - <%= Util.htmlize(dtag) %> + <%= Util.htmlize(cfg.getDefineTagsIndex()) %> en Copyright 2025 Java<% From 963fdc92b0c42c5225c9c433fc890c9442f89c45 Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Mon, 25 Aug 2025 17:14:32 +0200 Subject: [PATCH 5/9] encode the context path --- opengrok-web/src/main/webapp/rss.jsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opengrok-web/src/main/webapp/rss.jsp b/opengrok-web/src/main/webapp/rss.jsp index 833acf5c3fd..20b32471d55 100644 --- a/opengrok-web/src/main/webapp/rss.jsp +++ b/opengrok-web/src/main/webapp/rss.jsp @@ -95,7 +95,7 @@ org.opengrok.web.PageConfig" requestURL += ":" + port; } - requestURL += request.getContextPath(); + requestURL += Util.uriEncodePath(request.getContextPath()); requestURL += Prefix.HIST_L + Util.uriEncodePath(cfg.getPath()) + "#" + Util.uriEncode(entry.getRevision()); %><%= requestURL %> <% From 44546f6d1895522cc941318ad89389d6fa244706 Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Mon, 25 Aug 2025 17:21:37 +0200 Subject: [PATCH 6/9] simplify link creation --- opengrok-web/src/main/webapp/rss.jsp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/opengrok-web/src/main/webapp/rss.jsp b/opengrok-web/src/main/webapp/rss.jsp index 20b32471d55..6a4c2acdaf3 100644 --- a/opengrok-web/src/main/webapp/rss.jsp +++ b/opengrok-web/src/main/webapp/rss.jsp @@ -87,16 +87,16 @@ org.opengrok.web.PageConfig" String replaced = entry.getMessage().split("\n")[0]; %><%= Util.htmlize(entry.getRevision()) %> - <%= Util.htmlize(replaced) %> <% - String requestURL = request.getScheme() + "://"; - String serverName = cfg.getServerName(); - requestURL += serverName; - String port = Integer.toString(request.getLocalPort()); - if (!port.isEmpty()) { - requestURL += ":" + port; - } - - requestURL += Util.uriEncodePath(request.getContextPath()); - requestURL += Prefix.HIST_L + Util.uriEncodePath(cfg.getPath()) + "#" + Util.uriEncode(entry.getRevision()); + String requestURL = request.getScheme() + + "://" + + cfg.getServerName() + + ":" + + request.getLocalPort() + + Util.uriEncodePath(request.getContextPath()) + + Prefix.HIST_L + + Util.uriEncodePath(cfg.getPath()) + + "#" + + Util.uriEncode(entry.getRevision()); %><%= requestURL %> <% for (String e : entry.getMessage().split("\n")) { From 07bf5df16f63f2fded267c2d2c4abf76e4c00919 Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Mon, 25 Aug 2025 17:24:45 +0200 Subject: [PATCH 7/9] rename variable to fix nit --- opengrok-web/src/main/webapp/rss.jsp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opengrok-web/src/main/webapp/rss.jsp b/opengrok-web/src/main/webapp/rss.jsp index 6a4c2acdaf3..15c70d84d64 100644 --- a/opengrok-web/src/main/webapp/rss.jsp +++ b/opengrok-web/src/main/webapp/rss.jsp @@ -110,9 +110,9 @@ org.opengrok.web.PageConfig" if (cfg.isDir()) { Set files = entry.getFiles(); if (files != null) { - for (String ifile : files) { + for (String entryFile : files) { %> - <%= Util.htmlize(ifile) %><% + <%= Util.htmlize(entryFile) %><% } } } else { From 00359922410f3f248ef0e23c9b8c29b9e25ab08d Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Mon, 25 Aug 2025 17:31:03 +0200 Subject: [PATCH 8/9] rename for better readability --- opengrok-web/src/main/webapp/rss.jsp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/opengrok-web/src/main/webapp/rss.jsp b/opengrok-web/src/main/webapp/rss.jsp index 15c70d84d64..a75bcba1bc2 100644 --- a/opengrok-web/src/main/webapp/rss.jsp +++ b/opengrok-web/src/main/webapp/rss.jsp @@ -63,15 +63,15 @@ org.opengrok.web.PageConfig" en Copyright 2025 Java<% - History hist; + History history; if(cfg.isDir()) { - hist = new DirectoryHistoryReader(cfg.getHistoryDirs()).getHistory(); + history = new DirectoryHistoryReader(cfg.getHistoryDirs()).getHistory(); } else { - hist = HistoryGuru.getInstance().getHistory(cfg.getResourceFile()); + history = HistoryGuru.getInstance().getHistory(cfg.getResourceFile()); } - if (hist != null) { + if (history != null) { int i = 20; - for (HistoryEntry entry : hist.getHistoryEntries()) { + for (HistoryEntry entry : history.getHistoryEntries()) { if (i-- <= 0) { break; } From f281d3dbbfcf0867ad9cf0720f0d8fefa667caa7 Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Mon, 25 Aug 2025 17:32:26 +0200 Subject: [PATCH 9/9] add space --- opengrok-web/src/main/webapp/rss.jsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opengrok-web/src/main/webapp/rss.jsp b/opengrok-web/src/main/webapp/rss.jsp index a75bcba1bc2..e78e81c16a3 100644 --- a/opengrok-web/src/main/webapp/rss.jsp +++ b/opengrok-web/src/main/webapp/rss.jsp @@ -64,7 +64,7 @@ org.opengrok.web.PageConfig" Copyright 2025 Java<% History history; - if(cfg.isDir()) { + if (cfg.isDir()) { history = new DirectoryHistoryReader(cfg.getHistoryDirs()).getHistory(); } else { history = HistoryGuru.getInstance().getHistory(cfg.getResourceFile());