Skip to content

Commit 7834538

Browse files
committed
lucene 10.0.0 fix scheme recognition to work with URI
1 parent dc0ea9d commit 7834538

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

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

+13-9
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,11 @@ public static void encode(String s, Appendable dest) throws IOException {
677677
* @param urlStr string URL
678678
* @return the encoded URL
679679
* @throws URISyntaxException URI syntax
680-
* @throws MalformedURLException URL malformed
681680
*/
682-
public static String encodeURL(String urlStr) throws URISyntaxException, MalformedURLException {
681+
public static String encodeURL(String urlStr) throws URISyntaxException {
682+
// URL url = new URL(urlStr); - this call
683+
//FIXME - above can encode url parts somehow, while if you change it to URI, it won't be able to convert e.g.
684+
// http://www.example.com/"quotation"/else\ to http://www.example.com/"quotation"/else , see UtilTest:414
683685
URI constructed = new URI(urlStr);
684686
return constructed.toString();
685687
}
@@ -1465,7 +1467,11 @@ public static boolean isHttpUri(String string) {
14651467
} catch (URISyntaxException e) {
14661468
return false;
14671469
}
1468-
return uri.getScheme().equals("http") || uri.getScheme().equals("https");
1470+
String scheme = uri.getScheme();
1471+
if (scheme == null) {
1472+
return false;
1473+
}
1474+
return scheme.equals("http") || scheme.equals("https");
14691475
}
14701476

14711477
protected static final String REDACTED_USER_INFO = "redacted_by_OpenGrok";
@@ -1479,7 +1485,7 @@ public static String redactUrl(String path) {
14791485
URL url;
14801486
try {
14811487
url = (new URI(path)).toURL();
1482-
} catch (MalformedURLException | URISyntaxException e) {
1488+
} catch (MalformedURLException | URISyntaxException | IllegalArgumentException e) {
14831489
// not an URL
14841490
return path;
14851491
}
@@ -1524,7 +1530,7 @@ public static String linkify(String url, boolean newTab) {
15241530
attrs.put("rel", "noreferrer");
15251531
}
15261532
return buildLink(url, attrs);
1527-
} catch (URISyntaxException | MalformedURLException ex) {
1533+
} catch (URISyntaxException ex) {
15281534
return url;
15291535
}
15301536
}
@@ -1541,10 +1547,9 @@ public static String linkify(String url, boolean newTab) {
15411547
* @return string containing the result
15421548
*
15431549
* @throws URISyntaxException URI syntax
1544-
* @throws MalformedURLException malformed URL
15451550
*/
15461551
public static String buildLink(String name, Map<String, String> attrs)
1547-
throws URISyntaxException, MalformedURLException {
1552+
throws URISyntaxException {
15481553
StringBuilder buffer = new StringBuilder();
15491554
buffer.append("<a");
15501555
for (Entry<String, String> attr : attrs.entrySet()) {
@@ -1574,10 +1579,9 @@ public static String buildLink(String name, Map<String, String> attrs)
15741579
* @return string containing the result
15751580
*
15761581
* @throws URISyntaxException URI syntax
1577-
* @throws MalformedURLException bad URL
15781582
*/
15791583
public static String buildLink(String name, String url)
1580-
throws URISyntaxException, MalformedURLException {
1584+
throws URISyntaxException {
15811585
Map<String, String> attrs = new TreeMap<>();
15821586
attrs.put("href", url);
15831587
return buildLink(name, attrs);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ void testBuildLink() throws URISyntaxException, MalformedURLException {
453453

454454
@Test
455455
void testBuildLinkInvalidUrl1() {
456-
assertThrows(MalformedURLException.class, () -> Util.buildLink("link", "www.example.com")); // invalid protocol
456+
assertThrows(URISyntaxException.class, () -> Util.buildLink("link", "www.example.com")); // invalid protocol
457457
}
458458

459459
@Test

opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/SuggesterController.java

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import org.opengrok.web.api.v1.suggester.provider.filter.Suggester;
6363
import org.opengrok.web.api.v1.suggester.provider.service.SuggesterService;
6464

65-
import java.net.MalformedURLException;
6665
import java.net.URI;
6766
import java.net.URISyntaxException;
6867
import java.time.Duration;

suggester/src/main/java/org/opengrok/suggest/query/customized/CustomPhraseQuery.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,11 @@ public ScorerSupplier scorerSupplier(LeafReaderContext leafReaderContext) throws
293293

294294
if (query.slop == 0) {
295295
ArrayUtil.timSort(postingsFreqs);
296-
//TODO FIX
296+
//FIXME
297297
//return new CustomExactPhraseScorer(postingsFreqs, query.offset);
298298
return scorerSupplier(leafReaderContext);
299299
} else {
300-
//TODO FIX
300+
//FIXME
301301
//return new CustomSloppyPhraseScorer(postingsFreqs, query.slop, query.offset);
302302
return scorerSupplier(leafReaderContext);
303303
}

0 commit comments

Comments
 (0)