Skip to content

Commit 1e110b2

Browse files
authored
Fixed a bug with spaces in WorkflowIds when creating links in the UI. (#2874)
1 parent 20afdcb commit 1e110b2

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

temporal-sdk/src/main/java/io/temporal/internal/common/LinkConverter.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,19 @@ public class LinkConverter {
3232

3333
public static io.temporal.api.nexus.v1.Link workflowEventToNexusLink(Link.WorkflowEvent we) {
3434
try {
35+
3536
String url =
3637
String.format(
3738
linkPathFormat,
3839
URLEncoder.encode(we.getNamespace(), StandardCharsets.UTF_8.toString()),
39-
URLEncoder.encode(we.getWorkflowId(), StandardCharsets.UTF_8.toString()),
40+
// The 'replace' below handles spaces - the encoder will convert them to a plus,
41+
// which the UI then handles as a plus, thus breaking the link as the
42+
// space is lost.
43+
// It's a known quirk with the URLEncoder as it encodes for forms, not general URIs.
44+
// Only done for the WorkflowId as the other two are values we control,
45+
// and will never have spaces.
46+
URLEncoder.encode(we.getWorkflowId(), StandardCharsets.UTF_8.toString())
47+
.replace("+", "%20"),
4048
URLEncoder.encode(we.getRunId(), StandardCharsets.UTF_8.toString()));
4149

4250
List<Map.Entry<String, String>> queryParams = new ArrayList<>();

temporal-sdk/src/test/java/io/temporal/internal/common/LinkConverterTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
import io.temporal.api.common.v1.Link;
88
import io.temporal.api.enums.v1.EventType;
9+
import java.io.UnsupportedEncodingException;
10+
import java.net.URLDecoder;
11+
import java.nio.charset.StandardCharsets;
912
import org.junit.Test;
1013

1114
public class LinkConverterTest {
@@ -98,6 +101,35 @@ public void testConvertWorkflowEventToNexus_ValidSlash() {
98101
assertEquals(expected, actual);
99102
}
100103

104+
@Test
105+
public void testConvertWorkflowEventToNexus_ValidSpace() throws UnsupportedEncodingException {
106+
Link.WorkflowEvent input =
107+
Link.WorkflowEvent.newBuilder()
108+
.setNamespace("ns")
109+
.setWorkflowId("wf space+plus")
110+
.setRunId("run-id")
111+
.setEventRef(
112+
Link.WorkflowEvent.EventReference.newBuilder()
113+
.setEventId(1)
114+
.setEventType(EventType.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED))
115+
.build();
116+
117+
io.temporal.api.nexus.v1.Link expected =
118+
io.temporal.api.nexus.v1.Link.newBuilder()
119+
.setUrl(
120+
"temporal:///namespaces/ns/workflows/wf%20space%2Bplus/run-id/history?referenceType=EventReference&eventID=1&eventType=WorkflowExecutionStarted")
121+
.setType("temporal.api.common.v1.Link.WorkflowEvent")
122+
.build();
123+
124+
io.temporal.api.nexus.v1.Link actual = workflowEventToNexusLink(input);
125+
assertEquals(expected, actual);
126+
127+
String decoded = URLDecoder.decode(actual.getUrl(), StandardCharsets.UTF_8.toString());
128+
assertEquals(
129+
"temporal:///namespaces/ns/workflows/wf space+plus/run-id/history?referenceType=EventReference&eventID=1&eventType=WorkflowExecutionStarted",
130+
decoded);
131+
}
132+
101133
@Test
102134
public void testConvertWorkflowEventToNexus_ValidEventIDMissing() {
103135
Link.WorkflowEvent input =

0 commit comments

Comments
 (0)