From 78345383adcd964b54092f6e468dfdf22ec6c7a5 Mon Sep 17 00:00:00 2001 From: Lubos Kosco Date: Wed, 23 Oct 2024 15:18:00 +0200 Subject: [PATCH] lucene 10.0.0 fix scheme recognition to work with URI --- .../java/org/opengrok/indexer/web/Util.java | 22 +++++++++++-------- .../org/opengrok/indexer/web/UtilTest.java | 2 +- .../v1/controller/SuggesterController.java | 1 - .../query/customized/CustomPhraseQuery.java | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/web/Util.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/web/Util.java index 6066c3f70f4..2ada6f865e6 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/web/Util.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/web/Util.java @@ -677,9 +677,11 @@ public static void encode(String s, Appendable dest) throws IOException { * @param urlStr string URL * @return the encoded URL * @throws URISyntaxException URI syntax - * @throws MalformedURLException URL malformed */ - public static String encodeURL(String urlStr) throws URISyntaxException, MalformedURLException { + public static String encodeURL(String urlStr) throws URISyntaxException { + // URL url = new URL(urlStr); - this call + //FIXME - above can encode url parts somehow, while if you change it to URI, it won't be able to convert e.g. + // http://www.example.com/"quotation"/else\ to http://www.example.com/"quotation"/else , see UtilTest:414 URI constructed = new URI(urlStr); return constructed.toString(); } @@ -1465,7 +1467,11 @@ public static boolean isHttpUri(String string) { } catch (URISyntaxException e) { return false; } - return uri.getScheme().equals("http") || uri.getScheme().equals("https"); + String scheme = uri.getScheme(); + if (scheme == null) { + return false; + } + return scheme.equals("http") || scheme.equals("https"); } protected static final String REDACTED_USER_INFO = "redacted_by_OpenGrok"; @@ -1479,7 +1485,7 @@ public static String redactUrl(String path) { URL url; try { url = (new URI(path)).toURL(); - } catch (MalformedURLException | URISyntaxException e) { + } catch (MalformedURLException | URISyntaxException | IllegalArgumentException e) { // not an URL return path; } @@ -1524,7 +1530,7 @@ public static String linkify(String url, boolean newTab) { attrs.put("rel", "noreferrer"); } return buildLink(url, attrs); - } catch (URISyntaxException | MalformedURLException ex) { + } catch (URISyntaxException ex) { return url; } } @@ -1541,10 +1547,9 @@ public static String linkify(String url, boolean newTab) { * @return string containing the result * * @throws URISyntaxException URI syntax - * @throws MalformedURLException malformed URL */ public static String buildLink(String name, Map attrs) - throws URISyntaxException, MalformedURLException { + throws URISyntaxException { StringBuilder buffer = new StringBuilder(); buffer.append(" attr : attrs.entrySet()) { @@ -1574,10 +1579,9 @@ public static String buildLink(String name, Map attrs) * @return string containing the result * * @throws URISyntaxException URI syntax - * @throws MalformedURLException bad URL */ public static String buildLink(String name, String url) - throws URISyntaxException, MalformedURLException { + throws URISyntaxException { Map attrs = new TreeMap<>(); attrs.put("href", url); return buildLink(name, attrs); diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/web/UtilTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/web/UtilTest.java index 4487d259416..917735009fd 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/web/UtilTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/web/UtilTest.java @@ -453,7 +453,7 @@ void testBuildLink() throws URISyntaxException, MalformedURLException { @Test void testBuildLinkInvalidUrl1() { - assertThrows(MalformedURLException.class, () -> Util.buildLink("link", "www.example.com")); // invalid protocol + assertThrows(URISyntaxException.class, () -> Util.buildLink("link", "www.example.com")); // invalid protocol } @Test diff --git a/opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/SuggesterController.java b/opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/SuggesterController.java index 11e243d80db..4886ca44855 100644 --- a/opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/SuggesterController.java +++ b/opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/SuggesterController.java @@ -62,7 +62,6 @@ import org.opengrok.web.api.v1.suggester.provider.filter.Suggester; import org.opengrok.web.api.v1.suggester.provider.service.SuggesterService; -import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.time.Duration; diff --git a/suggester/src/main/java/org/opengrok/suggest/query/customized/CustomPhraseQuery.java b/suggester/src/main/java/org/opengrok/suggest/query/customized/CustomPhraseQuery.java index 6c0a4a7559f..0cce3f01a6e 100644 --- a/suggester/src/main/java/org/opengrok/suggest/query/customized/CustomPhraseQuery.java +++ b/suggester/src/main/java/org/opengrok/suggest/query/customized/CustomPhraseQuery.java @@ -293,11 +293,11 @@ public ScorerSupplier scorerSupplier(LeafReaderContext leafReaderContext) throws if (query.slop == 0) { ArrayUtil.timSort(postingsFreqs); - //TODO FIX + //FIXME //return new CustomExactPhraseScorer(postingsFreqs, query.offset); return scorerSupplier(leafReaderContext); } else { - //TODO FIX + //FIXME //return new CustomSloppyPhraseScorer(postingsFreqs, query.slop, query.offset); return scorerSupplier(leafReaderContext); }