Skip to content

Commit 0abcb6f

Browse files
javier-godoypaodb
authored andcommitted
fix!: interpret exception message as plain text instead of HTML
Close #74
1 parent 6afa8af commit 0abcb6f

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/main/java/com/flowingcode/vaadin/addons/errorwindow/ErrorWindow.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323

2424
import com.vaadin.flow.component.Component;
2525
import com.vaadin.flow.component.Html;
26+
import com.vaadin.flow.component.Text;
2627
import com.vaadin.flow.component.UI;
2728
import com.vaadin.flow.component.button.Button;
2829
import com.vaadin.flow.component.button.ButtonVariant;
2930
import com.vaadin.flow.component.dependency.CssImport;
3031
import com.vaadin.flow.component.dialog.Dialog;
3132
import com.vaadin.flow.component.html.Div;
33+
import com.vaadin.flow.component.html.Span;
3234
import com.vaadin.flow.component.icon.VaadinIcon;
3335
import com.vaadin.flow.component.orderedlayout.FlexComponent.Alignment;
3436
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
@@ -216,7 +218,7 @@ private VerticalLayout createMainLayout() {
216218
title.getElement().getStyle().set("width", "100%");
217219
mainLayout.add(title);
218220

219-
final Html errorLabel = createErrorLabel();
221+
Component errorLabel = createErrorLabel();
220222
mainLayout.add(errorLabel);
221223
mainLayout.setHorizontalComponentAlignment(Alignment.START, errorLabel);
222224

@@ -300,18 +302,21 @@ private String getStackTrace() {
300302
pw.flush();
301303
return baos.toString();
302304
}
303-
304-
protected Html createErrorLabel() {
305-
String label = errorMessage == null ? i18n.getDefaultErrorMessage() : errorMessage;
305+
306+
protected Component createErrorLabel() {
307+
Div errorLabel = new Div();
308+
errorLabel.setClassName("errorlabel");
309+
306310
if (productionMode) {
307-
label =
308-
label.concat(
309-
String.format(
310-
"<br />%s<br /><span class='uuid'>%s</span>",
311-
i18n.getInstructions(), uuid));
311+
Div instructions = new Div(new Text(i18n.getInstructions()));
312+
Span uuidSpan = new Span(uuid);
313+
uuidSpan.setClassName("uuid");
314+
errorLabel.add(instructions, uuidSpan);
315+
} else {
316+
String label = errorMessage == null ? i18n.getDefaultErrorMessage() : errorMessage;
317+
errorLabel.setText(label);
312318
}
313-
final Html errorLabel = new Html("<span>" + label + "</span>");
314-
errorLabel.getElement().getClassList().add("errorlabel");
319+
315320
return errorLabel;
316321
}
317322
}

0 commit comments

Comments
 (0)