Skip to content

Commit

Permalink
Merge pull request #3223 from ControlSystemStudio/fault_tolerant_url_…
Browse files Browse the repository at this point in the history
…parsing

Handle potentially invalid Olog resource URL
  • Loading branch information
shroffk authored Dec 31, 2024
2 parents 615dfed + 4f403a8 commit c9381d0
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 c9381d0

Please sign in to comment.