Skip to content

Commit c9381d0

Browse files
authored
Merge pull request #3223 from ControlSystemStudio/fault_tolerant_url_parsing
Handle potentially invalid Olog resource URL
2 parents 615dfed + 4f403a8 commit c9381d0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogPropertiesController.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.io.InputStream;
2727
import java.net.URI;
2828
import java.net.URL;
29+
import java.net.URLEncoder;
30+
import java.nio.charset.StandardCharsets;
2931
import java.util.*;
3032
import java.util.concurrent.atomic.AtomicReference;
3133
import java.util.logging.Level;
@@ -163,9 +165,16 @@ public void updateItem(Object item, boolean empty){
163165
break;
164166
case "resource":
165167
final String resourceURL = propertyItem.getValue();
166-
final URI resource = URI.create(resourceURL);
168+
URI _resource;
169+
try {
170+
_resource = URI.create(resourceURL);
171+
} catch (IllegalArgumentException e) { // E.g. if string contains space char
172+
logger.log(Level.WARNING, "Encountered invalid URL: \"" + resourceURL + "\", will be URL encoded.");
173+
_resource = URI.create(URLEncoder.encode(resourceURL, StandardCharsets.UTF_8));
174+
}
167175
final Hyperlink resourceLink = new Hyperlink(resourceURL);
168176
setGraphic(resourceLink);
177+
final URI resource = _resource;
169178
resourceLink.setOnAction((e) -> {
170179
final List<AppResourceDescriptor> applications = ApplicationService.getApplications(resource);
171180
// If resource URI contains valid app name, use it

0 commit comments

Comments
 (0)