Skip to content

Commit

Permalink
Additional workspace data sanatization
Browse files Browse the repository at this point in the history
  • Loading branch information
madhephaestus committed Jul 29, 2024
1 parent d9e8c28 commit 3d17280
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 37 deletions.
52 changes: 52 additions & 0 deletions src/main/java/com/neuronrobotics/bowlerstudio/BowlerStudio.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.transform.Affine;
import javafx.stage.Stage;

Expand All @@ -77,6 +79,8 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
Expand Down Expand Up @@ -1097,4 +1101,52 @@ public static TransformNR getTargetFrame() {
public static void loadMobilBaseIntoUI(MobileBase base) {
BowlerStudioController.getBowlerStudio().onScriptFinished(base, base, null);
}
public static void showExceptionAlert(Exception ex, String message) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText(message);
alert.setContentText(ex.getMessage());

StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
String stackTrace = sw.toString();

TextArea textArea = new TextArea(stackTrace);
textArea.setEditable(false);
textArea.setWrapText(true);

textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);

GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(textArea, 0, 0);

alert.getDialogPane().setExpandableContent(expContent);

alert.showAndWait();
}
public static boolean checkValidURL(String url) {
try {
if(url==null)
throw new NullPointerException();
if(url.length()<5)
throw new NullPointerException();
if(url.startsWith("http"))
new URL(url);// check that the URL string contains a valid URL
else
if(url.startsWith("git@")) {
// assume this is a URL
}
}catch(Exception e) {
// not a url
//
e.printStackTrace();
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.nio.file.WatchEvent;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -149,7 +150,9 @@ public void run() {
String message = BowlerStudioMenu.gitURLtoMessage(gitRepo);
if (gitRepo.length() < 5 || (message == null))
message = "Project " + gitRepo;
BowlerStudioMenuWorkspace.add(gitRepo, message);
if(BowlerStudio.checkValidURL(gitRepo)) {
BowlerStudioMenuWorkspace.add(gitRepo, message);
}
}
}
}.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,47 +91,16 @@ public static void loginEvent() {
public static void add(String url) {
add(url, BowlerStudioMenu.gitURLtoMessage(url));
}
public static void showExceptionAlert(Exception ex, String message) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText(message);
alert.setContentText(ex.getMessage());

StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
String stackTrace = sw.toString();

TextArea textArea = new TextArea(stackTrace);
textArea.setEditable(false);
textArea.setWrapText(true);

textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);

GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(textArea, 0, 0);

alert.getDialogPane().setExpandableContent(expContent);

alert.showAndWait();
}
@SuppressWarnings("unchecked")
public static void add(String url, String menueMessage) {
if (menueMessage == null)
throw new RuntimeException("Menu Message can not be " + menueMessage);
if (menueMessage.length() < 2) {
menueMessage = new Date().toString();
}
try {
new URL(url);// check that the URL string contains a valid URL
}catch(Exception e) {
// not a url
BowlerStudio.runLater(()->showExceptionAlert(e,"URL does not exist: "+url));
new IssueReportingExceptionHandler().except(e);
if(!BowlerStudio.checkValidURL(url)) {
BowlerStudio.runLater(()->BowlerStudio.showExceptionAlert(new RuntimeException(),"URL does not exist: "+url));
return;
}
ArrayList<String> data;
Expand All @@ -152,6 +121,8 @@ public static void add(String url, String menueMessage) {

}



@SuppressWarnings("unchecked")
public static void sort() {
if (sorting)
Expand Down Expand Up @@ -235,6 +206,7 @@ public static void sort() {
BowlerStudioMenu.setUpRepoMenue(workspaceMenu, url, false, false,
arrayList.get(0));
} catch (Throwable t) {
System.out.println("Error with "+url+" "+arrayList.toArray());
t.printStackTrace();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ private void load(ScriptingWidgetType type, File currentFile) {
try {
loadCodeFromFile(currentFile);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
// file has no git
isOwnedByLoggedInUser=false;
}
// publish.setDisable(!isOwnedByLoggedInUser);
runfx.setGraphic(AssetFactory.loadIcon("Run.png"));
Expand Down

0 comments on commit 3d17280

Please sign in to comment.