Skip to content

Commit a13a22d

Browse files
committed
Edge: Fix URI_FOR_CUSTOM_TEXT_PAGE in case of case mismatch
Use Path.equals() instead of URI.equals() to compare the URI paths. This will will handle upper/lower-case differences correctly which can arise, e.g. when symlinks are involved. Fixes #2061.
1 parent ad99d4e commit a13a22d

File tree

2 files changed

+66
-17
lines changed
  • bundles/org.eclipse.swt
    • Eclipse SWT Browser/win32/org/eclipse/swt/browser
    • Eclipse SWT Tests/win32/org/eclipse/swt/browser

2 files changed

+66
-17
lines changed

bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,8 +1534,10 @@ public void stop() {
15341534

15351535
static boolean isLocationForCustomText(String location) {
15361536
try {
1537-
return URI_FOR_CUSTOM_TEXT_PAGE.equals(new URI(location));
1538-
} catch (URISyntaxException e) {
1537+
URI locationUri = new URI(location);
1538+
return "file".equals(locationUri.getScheme())
1539+
&& Path.of(URI_FOR_CUSTOM_TEXT_PAGE).equals(Path.of(locationUri));
1540+
} catch (URISyntaxException | IllegalArgumentException e) {
15391541
return false;
15401542
}
15411543
}
Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,81 @@
11
package org.eclipse.swt.browser;
22

3+
import static org.junit.jupiter.api.Assertions.assertFalse;
34
import static org.junit.jupiter.api.Assertions.assertTrue;
45

56
import java.nio.file.*;
7+
import java.util.*;
68

79
import org.eclipse.swt.internal.*;
8-
import org.junit.jupiter.api.*;
10+
import org.junit.*;
11+
import org.junit.jupiter.api.Test;
912
import org.junit.jupiter.api.extension.*;
1013

1114
@ExtendWith(PlatformSpecificExecutionExtension.class)
1215
class EdgeTests {
1316

17+
private String originalTempDir;
18+
19+
@Before
20+
public void setup() throws Exception {
21+
originalTempDir = System.getProperty("java.io.tmpdir");
22+
}
23+
24+
@After
25+
public void tearDown() throws Exception {
26+
setTempDirAndInitializeEdgeLocationForCustomTextPage(originalTempDir);
27+
}
28+
29+
private static void setTempDirAndInitializeEdgeLocationForCustomTextPage(String dir) {
30+
System.setProperty("java.io.tmpdir", dir);
31+
Edge.setupLocationForCustomTextPage();
32+
}
33+
1434
/**
1535
* https://github.com/eclipse-platform/eclipse.platform.swt/issues/1912
1636
*/
1737
@Test
1838
public void handlingOfTempDirWithSpacesAndUnicodeCharacters() throws Exception {
19-
String originalTempDir = System.getProperty("java.io.tmpdir");
20-
String temporaryTempDirWithSpacesAndUnicode = Files.createTempDirectory("spaces and únîcòde").toString();
21-
System.setProperty("java.io.tmpdir", temporaryTempDirWithSpacesAndUnicode);
22-
try {
23-
Edge.setupLocationForCustomTextPage();
24-
25-
// URI_FOR_CUSTOM_TEXT_PAGE must already be encoded internally
26-
assertTrue(Edge.URI_FOR_CUSTOM_TEXT_PAGE.toString().contains("spaces%20and%20%C3%BAn%C3%AEc%C3%B2de"));
27-
assertTrue(Edge.isLocationForCustomText(Edge.URI_FOR_CUSTOM_TEXT_PAGE.toASCIIString()));
28-
29-
} finally {
30-
System.setProperty("java.io.tmpdir", originalTempDir);
31-
Edge.setupLocationForCustomTextPage(); // restore the original value
32-
}
39+
setTempDirAndInitializeEdgeLocationForCustomTextPage(
40+
Files.createTempDirectory("spaces and únîcòde").toString());
41+
42+
// URI_FOR_CUSTOM_TEXT_PAGE must already be encoded internally
43+
// for correct handling of spaces and unicode characters
44+
assertTrue(Edge.URI_FOR_CUSTOM_TEXT_PAGE.toString().contains("spaces%20and%20%C3%BAn%C3%AEc%C3%B2de"));
45+
assertTrue(Edge.isLocationForCustomText(Edge.URI_FOR_CUSTOM_TEXT_PAGE.toASCIIString()));
46+
}
47+
48+
/**
49+
* https://github.com/eclipse-platform/eclipse.platform.swt/issues/2061
50+
*/
51+
@Test
52+
public void handlingOfUpperLowerCase() throws Exception {
53+
setTempDirAndInitializeEdgeLocationForCustomTextPage(Files.createTempDirectory("FoObAr").toString());
54+
55+
String lowerCaseUri = Edge.URI_FOR_CUSTOM_TEXT_PAGE.toASCIIString().toLowerCase(Locale.ROOT);
56+
String upperCaseUri = "file"
57+
+ Edge.URI_FOR_CUSTOM_TEXT_PAGE.toASCIIString().toUpperCase(Locale.ROOT).substring(4);
58+
59+
assertTrue(Edge.isLocationForCustomText(lowerCaseUri));
60+
assertTrue(Edge.isLocationForCustomText(upperCaseUri));
61+
}
62+
63+
@Test
64+
public void handlingOfNonFileURIs() throws Exception {
65+
setTempDirAndInitializeEdgeLocationForCustomTextPage(Files.createTempDirectory("any").toString());
66+
67+
String httpsUri = "https://eclipse.org";
68+
69+
assertFalse(Edge.isLocationForCustomText(httpsUri));
3370
}
71+
72+
@Test
73+
public void handlingOfInvalidFileURIs() throws Exception {
74+
setTempDirAndInitializeEdgeLocationForCustomTextPage(Files.createTempDirectory("any").toString());
75+
76+
String brokenFileUri = "file://--";
77+
78+
assertFalse(Edge.isLocationForCustomText(brokenFileUri));
79+
}
80+
3481
}

0 commit comments

Comments
 (0)