Skip to content

Commit f234f26

Browse files
committed
add some robustness
1 parent 377bcbc commit f234f26

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Configuration.java

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.opengrok.indexer.authorization.AuthorizationStack;
6060
import org.opengrok.indexer.history.RepositoryInfo;
6161
import org.opengrok.indexer.logger.LoggerFactory;
62+
import org.opengrok.indexer.web.Util;
6263

6364
import static org.opengrok.indexer.configuration.PatternUtil.compilePattern;
6465

@@ -1642,5 +1643,12 @@ public void checkConfiguration() throws ConfigurationException {
16421643
LOGGER.log(Level.INFO, "History based reindex is on, however history cache is off. " +
16431644
"History cache has to be enabled for history based reindex.");
16441645
}
1646+
1647+
if (!Objects.isNull(getBugPage()) && !Util.isHttpUri(getBugPage())) {
1648+
throw new ConfigurationException("Bug page must be valid HTTP(S) URI");
1649+
}
1650+
if (!Objects.isNull(getReviewPage()) && !Util.isHttpUri(getReviewPage())) {
1651+
throw new ConfigurationException("Review page must be valid HTTP(S) URI");
1652+
}
16451653
}
16461654
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,9 @@ public static String buildLink(String name, String url, boolean newTab)
16031603
* @return replacement for the first group in the pattern
16041604
*/
16051605
private static String buildLinkReplacer(MatchResult result, String text, String url) {
1606+
if (result.groupCount() < 1) {
1607+
return result.group(0);
1608+
}
16061609
final String group1 = result.group(1);
16071610
final String appendedUrl = url + uriEncode(group1);
16081611
try {

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

+8
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,14 @@ void testLinkifyPatternEscape() {
494494
Util.linkifyPattern(text, Pattern.compile("[ \\t]+([0-9<>]{3,})[ \\t]*"), "http://www.example.com?bug="));
495495
}
496496

497+
@Test
498+
void testLinkifyPatternNoGroup() {
499+
final String text = "foo bug <123456> bar bug 777";
500+
501+
assertEquals(text,
502+
Util.linkifyPattern(text, Pattern.compile("[0-9]{3,}"), "http://www.example.com?bug="));
503+
}
504+
497505
@Test
498506
void testCompleteUrl() {
499507
HttpServletRequest req = new DummyHttpServletRequest() {

0 commit comments

Comments
 (0)