@@ -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 );
0 commit comments