Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions opengrok-indexer/src/main/java/org/opengrok/indexer/web/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("&nbsp;");
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}
Expand Down Expand Up @@ -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, ...
* <dl>
* <dt>for request http://localhost:8080/source/xref/xxx and part
* /cgi-bin/user=</dt>
* <dd>http://localhost:8080/cgi-bin/user=</dd>
* <dt>for request http://localhost:8080/source/xref/xxx and part
* cgi-bin/user=</dt>
* <dd>http://localhost:8080/source/xref/xxx/cgi-bin/user=</dd>
* <dt>for request http://localhost:8080/source/xref/xxx and part
* http://users.com/user=</dt>
* <dd>http://users.com/user=</dd>
* <dt>for request {@code http://localhost:8080/source/xref/xxx} and part {@code /cgi-bin/user=}</dt>
* <dd>{@code http://localhost:8080/cgi-bin/user=}</dd>
* <dt>for request {@code http://localhost:8080/source/xref/xxx} and part {@code cgi-bin/user=}</dt>
* <dd>{@code http://localhost:8080/source/xref/xxx/cgi-bin/user=}</dd>
* <dt>for request {@code http://localhost:8080/source/xref/xxx} and part
* {@code http://users.com/user=}</dt>
* <dd>{@code http://users.com/user=}</dd>
* </dl>
*
* @param url the given URL part, may be already full URL
Expand Down
2 changes: 2 additions & 0 deletions opengrok-web/src/main/java/org/opengrok/web/PageConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
49 changes: 24 additions & 25 deletions opengrok-web/src/main/webapp/rss.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,16 @@ 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);
}
return;
}
String path = cfg.getPath();
String dtag = cfg.getDefineTagsIndex();
response.setContentType("text/xml");
%><?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="<%= request.getContextPath()
Expand All @@ -60,19 +59,19 @@ org.opengrok.web.PageConfig"
<title>Changes in <%= path.isEmpty()
? "Cross Reference"
: Util.htmlize(cfg.getResourceFile().getName()) %></title>
<description><%= Util.htmlize(dtag) %></description>
<description><%= Util.htmlize(cfg.getDefineTagsIndex()) %></description>
<language>en</language>
<copyright>Copyright 2025</copyright>
<generator>Java</generator><%
History hist;
if(cfg.isDir()) {
hist = new DirectoryHistoryReader(cfg.getHistoryDirs()).getHistory();
History history;
if (cfg.isDir()) {
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;
}
Expand All @@ -88,17 +87,17 @@ org.opengrok.web.PageConfig"
String replaced = entry.getMessage().split("\n")[0];
%><%= Util.htmlize(entry.getRevision()) %> - <%= Util.htmlize(replaced) %></title>
<link><%
String requestURL = request.getScheme() + "://";
String serverName = cfg.getServerName();
requestURL += serverName;
String port = Integer.toString(request.getLocalPort());
if (!port.isEmpty()) {
requestURL += ":" + port;
}

requestURL += request.getContextPath();
requestURL += Prefix.HIST_L + cfg.getPath() + "#" + entry.getRevision();
%><%= Util.htmlize(requestURL) %></link>
String requestURL = request.getScheme() +
"://" +
cfg.getServerName() +
":" +
request.getLocalPort() +
Util.uriEncodePath(request.getContextPath()) +
Prefix.HIST_L +
Util.uriEncodePath(cfg.getPath()) +
"#" +
Util.uriEncode(entry.getRevision());
%><%= requestURL %></link>
<description><%
for (String e : entry.getMessage().split("\n")) {
%>
Expand All @@ -111,9 +110,9 @@ org.opengrok.web.PageConfig"
if (cfg.isDir()) {
Set<String> files = entry.getFiles();
if (files != null) {
for (String ifile : files) {
for (String entryFile : files) {
%>
<%= Util.htmlize(ifile) %><%
<%= Util.htmlize(entryFile) %><%
}
}
} else {
Expand Down
Loading