@@ -677,9 +677,11 @@ public static void encode(String s, Appendable dest) throws IOException {
677
677
* @param urlStr string URL
678
678
* @return the encoded URL
679
679
* @throws URISyntaxException URI syntax
680
- * @throws MalformedURLException URL malformed
681
680
*/
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
683
685
URI constructed = new URI (urlStr );
684
686
return constructed .toString ();
685
687
}
@@ -1465,7 +1467,11 @@ public static boolean isHttpUri(String string) {
1465
1467
} catch (URISyntaxException e ) {
1466
1468
return false ;
1467
1469
}
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" );
1469
1475
}
1470
1476
1471
1477
protected static final String REDACTED_USER_INFO = "redacted_by_OpenGrok" ;
@@ -1479,7 +1485,7 @@ public static String redactUrl(String path) {
1479
1485
URL url ;
1480
1486
try {
1481
1487
url = (new URI (path )).toURL ();
1482
- } catch (MalformedURLException | URISyntaxException e ) {
1488
+ } catch (MalformedURLException | URISyntaxException | IllegalArgumentException e ) {
1483
1489
// not an URL
1484
1490
return path ;
1485
1491
}
@@ -1524,7 +1530,7 @@ public static String linkify(String url, boolean newTab) {
1524
1530
attrs .put ("rel" , "noreferrer" );
1525
1531
}
1526
1532
return buildLink (url , attrs );
1527
- } catch (URISyntaxException | MalformedURLException ex ) {
1533
+ } catch (URISyntaxException ex ) {
1528
1534
return url ;
1529
1535
}
1530
1536
}
@@ -1541,10 +1547,9 @@ public static String linkify(String url, boolean newTab) {
1541
1547
* @return string containing the result
1542
1548
*
1543
1549
* @throws URISyntaxException URI syntax
1544
- * @throws MalformedURLException malformed URL
1545
1550
*/
1546
1551
public static String buildLink (String name , Map <String , String > attrs )
1547
- throws URISyntaxException , MalformedURLException {
1552
+ throws URISyntaxException {
1548
1553
StringBuilder buffer = new StringBuilder ();
1549
1554
buffer .append ("<a" );
1550
1555
for (Entry <String , String > attr : attrs .entrySet ()) {
@@ -1574,10 +1579,9 @@ public static String buildLink(String name, Map<String, String> attrs)
1574
1579
* @return string containing the result
1575
1580
*
1576
1581
* @throws URISyntaxException URI syntax
1577
- * @throws MalformedURLException bad URL
1578
1582
*/
1579
1583
public static String buildLink (String name , String url )
1580
- throws URISyntaxException , MalformedURLException {
1584
+ throws URISyntaxException {
1581
1585
Map <String , String > attrs = new TreeMap <>();
1582
1586
attrs .put ("href" , url );
1583
1587
return buildLink (name , attrs );
0 commit comments