Skip to content

Commit

Permalink
lucene 10.0.0 fix scheme recognition to work with URI
Browse files Browse the repository at this point in the history
  • Loading branch information
tarzanek committed Oct 24, 2024
1 parent dc0ea9d commit 7834538
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
22 changes: 13 additions & 9 deletions opengrok-indexer/src/main/java/org/opengrok/indexer/web/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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";
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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<String, String> attrs)
throws URISyntaxException, MalformedURLException {
throws URISyntaxException {
StringBuilder buffer = new StringBuilder();
buffer.append("<a");
for (Entry<String, String> attr : attrs.entrySet()) {
Expand Down Expand Up @@ -1574,10 +1579,9 @@ public static String buildLink(String name, Map<String, String> 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<String, String> attrs = new TreeMap<>();
attrs.put("href", url);
return buildLink(name, attrs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 7834538

Please sign in to comment.