Skip to content

Commit 7560b5f

Browse files
committed
Use URL encode and update test
1 parent f73c6a2 commit 7560b5f

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/io/flutter/devtools/DevToolsUrl.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class DevToolsUrl {
3737
private final boolean canUseMultiEmbed;
3838

3939
public final DevToolsIdeFeature ideFeature;
40+
private final String ideName;
4041

4142
@NotNull private final DevToolsUtils devToolsUtils;
4243

@@ -53,6 +54,7 @@ public static class Builder {
5354
private @Nullable FlutterSdkVersion flutterSdkVersion;
5455
private WorkspaceCache workspaceCache;
5556
private DevToolsIdeFeature ideFeature;
57+
private String ideName;
5658

5759
private DevToolsUtils devToolsUtils;
5860

@@ -133,6 +135,12 @@ public Builder setFlutterSdkUtil(FlutterSdkUtil flutterSdkUtil) {
133135
return this;
134136
}
135137

138+
@NotNull
139+
public Builder setIdeName(String ideName) {
140+
this.ideName = ideName;
141+
return this;
142+
}
143+
136144
@NotNull
137145
public DevToolsUrl build() {
138146
if (devToolsUtils == null) {
@@ -164,6 +172,7 @@ private DevToolsUrl(Builder builder) {
164172
this.flutterSdkVersion = builder.flutterSdkVersion;
165173
this.ideFeature = builder.ideFeature;
166174
this.sdkUtil = builder.flutterSdkUtil;
175+
this.ideName = builder.ideName != null ? builder.ideName : getIdeName();
167176

168177
if (builder.workspaceCache != null && builder.workspaceCache.isBazel()) {
169178
this.canUseMultiEmbed = true;
@@ -182,9 +191,10 @@ public String getUrlString() {
182191
final List<String> params = new ArrayList<>();
183192

184193
String ideValue = sdkUtil.getFlutterHostEnvValue();
185-
params.add("ide=" + (ideValue == null ? UNKNOWN_INTELLIJ_NAME : ideValue));
194+
String ideParamValue = ideValue == null ? UNKNOWN_INTELLIJ_NAME : ideValue;
195+
params.add("ide=" + URLEncoder.encode(ideParamValue, StandardCharsets.UTF_8));
186196
params.add("dashTool=intellij-plugins");
187-
params.add("dashIdeName=" + URLEncoder.encode(getIdeName(), StandardCharsets.UTF_8));
197+
params.add("dashIdeName=" + URLEncoder.encode(this.ideName, StandardCharsets.UTF_8));
188198
if (colorHexCode != null) {
189199
params.add("backgroundColor=" + colorHexCode);
190200
}

testSrc/unit/io/flutter/devtools/DevToolsUrlTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,25 @@ public void testGetUrlString() {
2020
DevToolsUrl.Builder builder = new DevToolsUrl.Builder()
2121
.setDevToolsHost("127.0.0.1")
2222
.setDevToolsPort(9100)
23-
.setVmServiceUri("http://127.0.0.1:12345/abc=");
23+
.setVmServiceUri("http://127.0.0.1:12345/abc=")
24+
.setIdeName("Test IDE Name");
2425

2526
// Mock FlutterSdkUtil to avoid calling real IntelliJ APIs which might fail in unit tests.
2627
builder.setFlutterSdkUtil(new FlutterSdkUtil() {
2728
@Override
2829
public String getFlutterHostEnvValue() {
29-
return "TestIDE";
30+
return "Test:IDE";
3031
}
3132
});
3233

3334
DevToolsUrl devToolsUrl = builder.build();
3435
String url = devToolsUrl.getUrlString();
3536

36-
assertTrue(url.contains("ide=TestIDE"));
37+
// Test:IDE encoded becomes Test%3AIDE
38+
assertTrue(url.contains("ide=Test%3AIDE"));
3739
assertTrue(url.contains("dashTool=intellij-plugins"));
3840

39-
// We check that dashIdeName is present. We don't assert the exact value because it depends on the environment
40-
// (whether ApplicationInfo is initialized or returns null).
41-
assertTrue(url.contains("dashIdeName="));
41+
// Test IDE Name encoded becomes Test+IDE+Name
42+
assertTrue(url.contains("dashIdeName=Test+IDE+Name"));
4243
}
4344
}

0 commit comments

Comments
 (0)