-
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix: remove unsafe exec() in App.java #3471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9ac6885
296c731
57e65b2
65fc792
897ed32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |||||||||||||||||||||
| import java.awt.Desktop; | ||||||||||||||||||||||
| import java.io.File; | ||||||||||||||||||||||
| import java.io.IOException; | ||||||||||||||||||||||
| import java.util.Locale; | ||||||||||||||||||||||
| import lombok.extern.slf4j.Slf4j; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
|
|
@@ -77,8 +78,24 @@ public static void main(String[] args) { | |||||||||||||||||||||
| Desktop.getDesktop().open(applicationFile); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| // java Desktop not supported - above unlikely to work for Windows so try instead... | ||||||||||||||||||||||
| Runtime.getRuntime().exec("cmd.exe start " + applicationFile); | ||||||||||||||||||||||
| // java Desktop not supported - use ProcessBuilder for cross-platform support | ||||||||||||||||||||||
| var os = System.getProperty("os.name").toLowerCase(Locale.ROOT); | ||||||||||||||||||||||
| ProcessBuilder pb; | ||||||||||||||||||||||
| if (os.contains("win")) { | ||||||||||||||||||||||
| // Empty string title arg prevents cmd start treating a quoted path as the window title | ||||||||||||||||||||||
| pb = | ||||||||||||||||||||||
| new ProcessBuilder( | ||||||||||||||||||||||
| "C:\\Windows\\System32\\cmd.exe", | ||||||||||||||||||||||
| "/c", | ||||||||||||||||||||||
| "start", | ||||||||||||||||||||||
| "", | ||||||||||||||||||||||
| applicationFile.getAbsolutePath()); | ||||||||||||||||||||||
|
Comment on lines
+87
to
+92
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Windows start command treats the first quoted argument as the window title. If the user's workspace path or checkout path contains spaces (which is very common), |
||||||||||||||||||||||
| } else if (os.contains("mac")) { | ||||||||||||||||||||||
| pb = new ProcessBuilder("open", applicationFile.getAbsolutePath()); // NOSONAR | ||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| pb = new ProcessBuilder("xdg-open", applicationFile.getAbsolutePath()); // NOSONAR | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| pb.start(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| } catch (IOException ex) { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistency with the main page-object App.java implementation.
The main module's App.java has a much simpler fallback block without operating system checks or hardcoded path names. Maintaining two different styles of fallbacks for the same logical behavior is unnecessary.
Align the fix implementation with the one used in main page-object App.java.