Skip to content

Commit 0561895

Browse files
committed
Fix uniqueDefinition handling
- Size is wrong for /s prefix. - Marshal definition name via query parameter to accomodate rev redirect.
1 parent bee0118 commit 0561895

File tree

5 files changed

+54
-10
lines changed

5 files changed

+54
-10
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
@@ -1355,6 +1355,11 @@ public String getRevisionLocation(String revStr) {
13551355
sb.append("&");
13561356
sb.append(req.getQueryString());
13571357
}
1358+
String frag = req.getParameter(QueryParameters.FRAGMENT_IDENTIFIER_PARAM);
1359+
if (frag != null) {
1360+
sb.append("#");
1361+
sb.append(Util.URIEncode(frag));
1362+
}
13581363

13591364
return sb.toString();
13601365
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
/*
2121
* Copyright (c) 2011 Jens Elkner.
2222
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
23+
* Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
2324
*/
2425
package org.opengrok.indexer.web;
2526

@@ -105,7 +106,7 @@ public String toString() {
105106
* @see #toString()
106107
*/
107108
public static Prefix get(String servletPath) {
108-
if (servletPath == null || servletPath.length() < 3 || servletPath.charAt(0) != '/') {
109+
if (servletPath == null || servletPath.length() < 2 || servletPath.charAt(0) != '/') {
109110
return UNKNOWN;
110111
}
111112
int idx = servletPath.indexOf('/', 1);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ public class QueryParameters {
7777
*/
7878
public static final String FORMAT_PARAM_EQ = FORMAT_PARAM + "=";
7979

80+
/**
81+
* Parameter name to specify a mediated fragment identifier.
82+
*/
83+
public static final String FRAGMENT_IDENTIFIER_PARAM = "fi";
84+
85+
/**
86+
* {@link #FRAGMENT_IDENTIFIER_PARAM} concatenated with {@code "=" }.
87+
*/
88+
public static final String FRAGMENT_IDENTIFIER_PARAM_EQ = FRAGMENT_IDENTIFIER_PARAM + "=";
89+
8090
/**
8191
* Parameter name to specify an OpenGrok full search.
8292
*/

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,11 @@ public SearchHelper executeQuery() {
413413
}
414414
}
415415
if (uniqueDefinition) {
416+
String anchor = Util.URIEncode(((TermQuery) query).getTerm().text());
416417
redirect = contextPath + Prefix.XREF_P
417418
+ Util.URIEncodePath(searcher.doc(hits[0].doc).get(QueryBuilder.PATH))
418-
+ '#' + Util.URIEncode(((TermQuery) query).getTerm().text());
419+
+ '?' + QueryParameters.FRAGMENT_IDENTIFIER_PARAM_EQ + anchor
420+
+ '#' + anchor;
419421
}
420422
} catch (BooleanQuery.TooManyClauses e) {
421423
errorMsg = "Too many results for wildcard!";

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

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919

2020
/*
2121
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.indexer.web;
2425

2526
import java.io.BufferedReader;
2627
import java.io.IOException;
2728
import java.io.UnsupportedEncodingException;
2829
import java.security.Principal;
30+
import java.util.Arrays;
2931
import java.util.Collection;
3032
import java.util.Collections;
3133
import java.util.Enumeration;
@@ -66,7 +68,9 @@
6668
public class DummyHttpServletRequest implements HttpServletRequest {
6769

6870
private final Map<String, Object> attrs = new HashMap<>();
69-
71+
72+
private Map<String, String[]> parameters = Collections.emptyMap();
73+
7074
private class DummyHttpSession implements HttpSession {
7175
private Map<String, Object> attrs = new HashMap<>();
7276

@@ -159,7 +163,7 @@ public boolean isNew() {
159163
};
160164

161165
private HttpSession session;
162-
166+
163167
@Override
164168
public String getAuthType() {
165169
throw new UnsupportedOperationException("Not supported yet.");
@@ -368,23 +372,45 @@ public ServletInputStream getInputStream() throws IOException {
368372
}
369373

370374
@Override
371-
public String getParameter(String string) {
372-
throw new UnsupportedOperationException("Not supported yet.");
375+
public String getParameter(String name) {
376+
String[] values = parameters.get(name);
377+
if (values != null && values.length > 0) {
378+
return values[0];
379+
} else {
380+
return null;
381+
}
373382
}
374383

375384
@Override
376385
public Enumeration<String> getParameterNames() {
377-
throw new UnsupportedOperationException("Not supported yet.");
386+
return Collections.enumeration(parameters.keySet());
378387
}
379388

380389
@Override
381-
public String[] getParameterValues(String string) {
382-
throw new UnsupportedOperationException("Not supported yet.");
390+
public String[] getParameterValues(String name) {
391+
return parameters.get(name);
383392
}
384393

385394
@Override
386395
public Map<String, String[]> getParameterMap() {
387-
throw new UnsupportedOperationException("Not supported yet.");
396+
return Collections.unmodifiableMap(parameters);
397+
}
398+
399+
public void setParameterMap(Map<String, String[]> parameters) {
400+
if (parameters == null) {
401+
this.parameters = Collections.emptyMap();
402+
} else {
403+
this.parameters = new HashMap<>(parameters);
404+
for (Map.Entry<String, String[]> entry : parameters.entrySet()) {
405+
String[] values;
406+
if (entry.getValue() == null) {
407+
values = new String[0];
408+
} else {
409+
values = Arrays.copyOf(entry.getValue(), entry.getValue().length);
410+
}
411+
this.parameters.put(entry.getKey(), values);
412+
}
413+
}
388414
}
389415

390416
@Override

0 commit comments

Comments
 (0)