Skip to content

Commit 1213397

Browse files
authored
Merge pull request #3594 from ControlSystemStudio/CSSTUDIO-3488
Escape HTML in Olog logs
2 parents a05258a + adcfec5 commit 1213397

File tree

8 files changed

+62
-14
lines changed

8 files changed

+62
-14
lines changed

app/logbook/olog/client-es/src/main/java/org/phoebus/olog/es/api/OlogHttpClient.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,14 @@ private SearchResult findLogs(MultivaluedMap<String, String> searchParams) throw
260260
.build();
261261
try {
262262
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
263-
OlogSearchResult searchResult = OlogObjectMappers.logEntryDeserializer.readValue(response.body(), OlogSearchResult.class);
264-
return SearchResult.of(new ArrayList<>(searchResult.getLogs()),
265-
searchResult.getHitCount());
263+
if(response.statusCode() == 200) {
264+
OlogSearchResult searchResult = OlogObjectMappers.logEntryDeserializer.readValue(response.body(), OlogSearchResult.class);
265+
return SearchResult.of(new ArrayList<>(searchResult.getLogs()),
266+
searchResult.getHitCount());
267+
}
268+
else{
269+
throw new RuntimeException(response.body());
270+
}
266271
} catch (Exception e) {
267272
LOGGER.log(Level.WARNING, "failed to retrieve log entries", e);
268273
throw new RuntimeException(e);

app/logbook/olog/ui/doc/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ Features
2121

2222
- Log entry viewers offer search capabilities based on meta data and content.
2323

24+
Missing features
25+
----------------
26+
In contrast to other markup implementations, HTML tags are **not** supported. Any such tags entered by user will
27+
be rendered as plain text.
28+
29+
2430
Launching the log entry editor
2531
------------------------------
2632
The log entry editor is launched as a non-modal window using one of the following methods:

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,38 @@
2929

3030
public class HtmlAwareController {
3131

32-
private Parser parser;
33-
private HtmlRenderer htmlRenderer;
32+
private final Parser parser;
33+
private final HtmlRenderer htmlRenderer;
3434

35+
/**
36+
* Constructor to generate html code for HTML preview feature in LogEntryEditor or detailed log entry view.
37+
* @param serviceUrl Olog service url
38+
*/
3539
public HtmlAwareController(String serviceUrl){
36-
List<Extension> extensions =
37-
Arrays.asList(TablesExtension.create(), ImageAttributesExtension.create());
38-
this.parser = Parser.builder().extensions(extensions).build();
39-
htmlRenderer = HtmlRenderer.builder()
40-
.attributeProviderFactory(context -> new OlogAttributeProvider(serviceUrl))
41-
.extensions(extensions).build();
40+
this(new OlogAttributeProvider(serviceUrl));
4241
}
4342

4443
/**
45-
* To create HtmlAwareController object to generate html code for HTML preview feature in LogEntryEditor.
44+
* Constructor to generate html code for HTML preview feature in LogEntryEditor or detailed log entry view.
4645
* @param serviceUrl Olog service url.
4746
* @param preview Set true when preview button is clicked.
4847
* @param attachments The current attachments list from AttachmentsEditorController.
4948
*/
5049
public HtmlAwareController(String serviceUrl, boolean preview, List<Attachment> attachments){
50+
this(new OlogAttributeProvider(serviceUrl, preview, attachments));
51+
}
52+
53+
/**
54+
* Private constructor to avoid code duplication.
55+
* @param ologAttributeProvider The {@link OlogAttributeProvider} particular to the use case.
56+
*/
57+
private HtmlAwareController(OlogAttributeProvider ologAttributeProvider){
5158
List<Extension> extensions =
5259
Arrays.asList(TablesExtension.create(), ImageAttributesExtension.create());
5360
this.parser = Parser.builder().extensions(extensions).build();
5461
htmlRenderer = HtmlRenderer.builder()
55-
.attributeProviderFactory(context -> new OlogAttributeProvider(serviceUrl, preview, attachments))
62+
.escapeHtml(true)
63+
.attributeProviderFactory(context -> ologAttributeProvider)
5664
.extensions(extensions).build();
5765
}
5866

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.phoebus.logbook.SearchResult;
3535
import org.phoebus.logbook.olog.ui.query.OlogQuery;
3636
import org.phoebus.logbook.olog.ui.query.OlogQueryManager;
37+
import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog;
3738

3839
import java.net.URL;
3940
import java.time.LocalDateTime;
@@ -262,7 +263,8 @@ public void search() {
262263
},
263264
(msg, ex) -> {
264265
searchInProgress.set(false);
265-
});
266+
ExceptionDetailsErrorDialog.openError(agenda, Messages.SearchFailed, "", ex);
267+
});
266268
}
267269

268270
public String getQuery() {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javafx.scene.control.Pagination;
2626
import javafx.scene.control.ProgressIndicator;
2727
import javafx.scene.control.SelectionMode;
28+
import javafx.scene.control.SplitPane;
2829
import javafx.scene.control.TableCell;
2930
import javafx.scene.control.TableColumn;
3031
import javafx.scene.control.TableView;
@@ -60,6 +61,7 @@
6061
import org.phoebus.security.store.SecureStore;
6162
import org.phoebus.security.tokens.ScopedAuthenticationToken;
6263
import org.phoebus.ui.dialog.DialogHelper;
64+
import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog;
6365

6466
import java.io.IOException;
6567
import java.util.ArrayList;
@@ -88,6 +90,10 @@ public class LogEntryTableViewController extends LogbookSearchController impleme
8890
@SuppressWarnings("unused")
8991
private GridPane viewSearchPane;
9092

93+
@SuppressWarnings("unused")
94+
@FXML
95+
private SplitPane splitPane;
96+
9197
// elements related to the table view of the log entries
9298
@FXML
9399
@SuppressWarnings("unused")
@@ -420,6 +426,7 @@ public void search() {
420426
},
421427
(msg, ex) -> {
422428
searchInProgress.set(false);
429+
ExceptionDetailsErrorDialog.openError(splitPane, Messages.SearchFailed, "", ex);
423430
});
424431
}
425432

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class Messages
5555
PreviewOpenErrorTitle,
5656
ReplyToLogEntry,
5757
RequestTooLarge,
58+
SearchFailed,
5859
SelectFile,
5960
SelectFolder,
6061
ShowHideDetails,

app/logbook/olog/ui/src/main/resources/org/phoebus/logbook/olog/ui/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ ScalingFactor=Scaling Factor
9494
SearchButtonText=Search:
9595
Search=Search available:
9696
SearchAvailableItems=Search the list of available items.
97+
SearchFailed=Search Failed
9798
SearchToolTip=Edit and press Enter to search
9899
Selected=Selected
99100
SelectFolder=Select Folder
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (C) 2025 European Spallation Source ERIC.
3+
*/
4+
5+
package org.phoebus.logbook.olog.ui;
6+
7+
import org.junit.jupiter.api.Test;
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
public class HtmlAwareControllerTest {
11+
12+
@Test
13+
public void testEscapeHtml(){
14+
HtmlAwareController htmlAwareController = new HtmlAwareController("");
15+
String escapedHtml = htmlAwareController.toHtml("<br><p>Paragraph</p>");
16+
assertEquals("<p>&lt;br&gt;&lt;p&gt;Paragraph&lt;/p&gt;</p>\n", escapedHtml);
17+
}
18+
}

0 commit comments

Comments
 (0)