Skip to content

Commit

Permalink
Handle potentially invalid Olog resource URL
Browse files Browse the repository at this point in the history
  • Loading branch information
georgweiss committed Dec 30, 2024
1 parent 6a1ea77 commit 4f403a8
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
Expand Down Expand Up @@ -163,9 +165,16 @@ public void updateItem(Object item, boolean empty){
break;
case "resource":
final String resourceURL = propertyItem.getValue();
final URI resource = URI.create(resourceURL);
URI _resource;
try {
_resource = URI.create(resourceURL);
} catch (IllegalArgumentException e) { // E.g. if string contains space char
logger.log(Level.WARNING, "Encountered invalid URL: \"" + resourceURL + "\", will be URL encoded.");
_resource = URI.create(URLEncoder.encode(resourceURL, StandardCharsets.UTF_8));
}
final Hyperlink resourceLink = new Hyperlink(resourceURL);
setGraphic(resourceLink);
final URI resource = _resource;
resourceLink.setOnAction((e) -> {
final List<AppResourceDescriptor> applications = ApplicationService.getApplications(resource);
// If resource URI contains valid app name, use it
Expand Down

0 comments on commit 4f403a8

Please sign in to comment.