Skip to content

Commit

Permalink
Fix logic to find driver version from CfT URL (should prevent #1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Nov 6, 2023
1 parent 2901534 commit 6299f0b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/main/java/io/github/bonigarcia/wdm/WebDriverManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public abstract class WebDriverManager {
protected static final String SLASH = "/";
protected static final String DASH = "-";
protected static final String LATEST_RELEASE = "LATEST_RELEASE";
protected static final String CFT_LABEL = "chrome-for-testing";
protected static final NamespaceContext S3_NAMESPACE_CONTEXT = new S3NamespaceContext();
protected static final String IN_DOCKER = "-in-docker";
protected static final String CLI_SERVER = "server";
Expand Down Expand Up @@ -1387,6 +1388,10 @@ protected String getCurrentVersion(URL url) {
int i = url.getFile().lastIndexOf(SLASH);
int j = url.getFile().substring(0, i).lastIndexOf(SLASH) + 1;
return url.getFile().substring(j, i);
} else if (url.getFile().contains(CFT_LABEL)) {
int i = url.getFile().indexOf(CFT_LABEL) + CFT_LABEL.length();
int j = url.getFile().indexOf(SLASH, i + 1);
return url.getFile().substring(i + 1, j);
} else {
String currentVersion = "";
String pattern = "/([^/]*?)/[^/]*?" + getShortDriverName();
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/io/github/bonigarcia/wdm/online/UrlHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,22 @@ public void filterByLatestVersion(Function<URL, String> getCurrentVersion) {
candidateUrls);
List<URL> out = new ArrayList<>();
List<URL> copyOfList = new ArrayList<>(candidateUrls);
String foundFriverVersion = null;
String foundDriverVersion = null;

for (URL url : copyOfList) {
try {
if (isNotStable(url)) {
continue;
}
String currentVersion = getCurrentVersion.apply(url);
if (isNullOrEmpty(foundFriverVersion)) {
foundFriverVersion = currentVersion;
if (isNullOrEmpty(foundDriverVersion)) {
foundDriverVersion = currentVersion;
}
if (versionCompare(currentVersion, foundFriverVersion) > 0) {
foundFriverVersion = currentVersion;
if (versionCompare(currentVersion, foundDriverVersion) > 0) {
foundDriverVersion = currentVersion;
out.clear();
}
if (url.getFile().contains(foundFriverVersion)) {
if (url.getFile().contains(foundDriverVersion)) {
out.add(url);
}
} catch (Exception e) {
Expand All @@ -118,7 +118,7 @@ public void filterByLatestVersion(Function<URL, String> getCurrentVersion) {
}
}

this.driverVersion = foundFriverVersion;
this.driverVersion = foundDriverVersion;
this.candidateUrls = out;
}

Expand Down

0 comments on commit 6299f0b

Please sign in to comment.