Skip to content

Commit b948608

Browse files
author
Vladimir Kotal
authored
preserve query string from the request when building reivision redirect (#2494)
fixes #2492
1 parent 89524e9 commit b948608

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,11 @@ public String getRevisionLocation(String revStr) {
12881288
sb.append("?r=");
12891289
sb.append(Util.URIEncode(revStr));
12901290

1291+
if (req.getQueryString() != null) {
1292+
sb.append("&");
1293+
sb.append(req.getQueryString());
1294+
}
1295+
12911296
return sb.toString();
12921297
}
12931298

opengrok-indexer/src/test/java/org/opengrok/indexer/web/PageConfigTest.java

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ public String getParameter(String name) {
246246
public void testGetLatestRevisionValid() {
247247
DummyHttpServletRequest req1 = new DummyHttpServletRequest() {
248248
@Override
249-
public String getPathInfo() {
250-
return "/git/main.c";
249+
public String getPathInfo() {
250+
return "/git/main.c";
251251
}
252252
};
253253

@@ -257,6 +257,58 @@ public String getPathInfo() {
257257
assertEquals("aa35c258", rev);
258258
}
259259

260+
@Test
261+
public void testGetRevisionLocation() {
262+
DummyHttpServletRequest req1 = new DummyHttpServletRequest() {
263+
@Override
264+
public String getPathInfo() {
265+
return "/git/main.c";
266+
}
267+
268+
@Override
269+
public String getContextPath() {
270+
return "source";
271+
}
272+
273+
@Override
274+
public String getQueryString() {
275+
return "a=true";
276+
}
277+
};
278+
279+
PageConfig cfg = PageConfig.get(req1);
280+
281+
String location = cfg.getRevisionLocation(cfg.getLatestRevision());
282+
assertNotNull(location);
283+
assertEquals("source/xref/git/main.c?r=aa35c258&a=true", location);
284+
}
285+
286+
@Test
287+
public void testGetRevisionLocationNullQuery() {
288+
DummyHttpServletRequest req1 = new DummyHttpServletRequest() {
289+
@Override
290+
public String getPathInfo() {
291+
return "/git/main.c";
292+
}
293+
294+
@Override
295+
public String getContextPath() {
296+
return "source";
297+
}
298+
299+
@Override
300+
public String getQueryString() {
301+
return null;
302+
}
303+
};
304+
305+
PageConfig cfg = PageConfig.get(req1);
306+
307+
String location = cfg.getRevisionLocation(cfg.getLatestRevision());
308+
assertNotNull(location);
309+
assertEquals("source/xref/git/main.c?r=aa35c258", location);
310+
}
311+
260312
@Test
261313
public void testGetLatestRevisionNotValid() {
262314
DummyHttpServletRequest req2 = new DummyHttpServletRequest() {

0 commit comments

Comments
 (0)