Skip to content

Commit 3d17280

Browse files
committed
Additional workspace data sanatization
1 parent d9e8c28 commit 3d17280

File tree

5 files changed

+64
-37
lines changed

5 files changed

+64
-37
lines changed

src/main/java/com/neuronrobotics/bowlerstudio/BowlerStudio.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
import javafx.scene.control.Alert.AlertType;
5252
import javafx.scene.control.TextArea;
5353
import javafx.scene.image.Image;
54+
import javafx.scene.layout.GridPane;
55+
import javafx.scene.layout.Priority;
5456
import javafx.scene.transform.Affine;
5557
import javafx.stage.Stage;
5658

@@ -77,6 +79,8 @@
7779
import java.io.InputStreamReader;
7880
import java.io.OutputStream;
7981
import java.io.PrintStream;
82+
import java.io.PrintWriter;
83+
import java.io.StringWriter;
8084
import java.net.MalformedURLException;
8185
import java.net.URI;
8286
import java.net.URL;
@@ -1097,4 +1101,52 @@ public static TransformNR getTargetFrame() {
10971101
public static void loadMobilBaseIntoUI(MobileBase base) {
10981102
BowlerStudioController.getBowlerStudio().onScriptFinished(base, base, null);
10991103
}
1104+
public static void showExceptionAlert(Exception ex, String message) {
1105+
Alert alert = new Alert(Alert.AlertType.ERROR);
1106+
alert.setTitle("Error");
1107+
alert.setHeaderText(message);
1108+
alert.setContentText(ex.getMessage());
1109+
1110+
StringWriter sw = new StringWriter();
1111+
PrintWriter pw = new PrintWriter(sw);
1112+
ex.printStackTrace(pw);
1113+
String stackTrace = sw.toString();
1114+
1115+
TextArea textArea = new TextArea(stackTrace);
1116+
textArea.setEditable(false);
1117+
textArea.setWrapText(true);
1118+
1119+
textArea.setMaxWidth(Double.MAX_VALUE);
1120+
textArea.setMaxHeight(Double.MAX_VALUE);
1121+
GridPane.setVgrow(textArea, Priority.ALWAYS);
1122+
GridPane.setHgrow(textArea, Priority.ALWAYS);
1123+
1124+
GridPane expContent = new GridPane();
1125+
expContent.setMaxWidth(Double.MAX_VALUE);
1126+
expContent.add(textArea, 0, 0);
1127+
1128+
alert.getDialogPane().setExpandableContent(expContent);
1129+
1130+
alert.showAndWait();
1131+
}
1132+
public static boolean checkValidURL(String url) {
1133+
try {
1134+
if(url==null)
1135+
throw new NullPointerException();
1136+
if(url.length()<5)
1137+
throw new NullPointerException();
1138+
if(url.startsWith("http"))
1139+
new URL(url);// check that the URL string contains a valid URL
1140+
else
1141+
if(url.startsWith("git@")) {
1142+
// assume this is a URL
1143+
}
1144+
}catch(Exception e) {
1145+
// not a url
1146+
//
1147+
e.printStackTrace();
1148+
return false;
1149+
}
1150+
return true;
1151+
}
11001152
}

src/main/java/com/neuronrobotics/bowlerstudio/BowlerStudioController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.io.IOException;
4848
import java.io.PrintWriter;
4949
import java.io.StringWriter;
50+
import java.net.MalformedURLException;
5051
import java.nio.file.WatchEvent;
5152
import java.util.ArrayList;
5253
import java.util.Collection;
@@ -149,7 +150,9 @@ public void run() {
149150
String message = BowlerStudioMenu.gitURLtoMessage(gitRepo);
150151
if (gitRepo.length() < 5 || (message == null))
151152
message = "Project " + gitRepo;
152-
BowlerStudioMenuWorkspace.add(gitRepo, message);
153+
if(BowlerStudio.checkValidURL(gitRepo)) {
154+
BowlerStudioMenuWorkspace.add(gitRepo, message);
155+
}
153156
}
154157
}
155158
}.start();

src/main/java/com/neuronrobotics/bowlerstudio/BowlerStudioMenuWorkspace.java

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -91,47 +91,16 @@ public static void loginEvent() {
9191
public static void add(String url) {
9292
add(url, BowlerStudioMenu.gitURLtoMessage(url));
9393
}
94-
public static void showExceptionAlert(Exception ex, String message) {
95-
Alert alert = new Alert(Alert.AlertType.ERROR);
96-
alert.setTitle("Error");
97-
alert.setHeaderText(message);
98-
alert.setContentText(ex.getMessage());
9994

100-
StringWriter sw = new StringWriter();
101-
PrintWriter pw = new PrintWriter(sw);
102-
ex.printStackTrace(pw);
103-
String stackTrace = sw.toString();
104-
105-
TextArea textArea = new TextArea(stackTrace);
106-
textArea.setEditable(false);
107-
textArea.setWrapText(true);
108-
109-
textArea.setMaxWidth(Double.MAX_VALUE);
110-
textArea.setMaxHeight(Double.MAX_VALUE);
111-
GridPane.setVgrow(textArea, Priority.ALWAYS);
112-
GridPane.setHgrow(textArea, Priority.ALWAYS);
113-
114-
GridPane expContent = new GridPane();
115-
expContent.setMaxWidth(Double.MAX_VALUE);
116-
expContent.add(textArea, 0, 0);
117-
118-
alert.getDialogPane().setExpandableContent(expContent);
119-
120-
alert.showAndWait();
121-
}
12295
@SuppressWarnings("unchecked")
12396
public static void add(String url, String menueMessage) {
12497
if (menueMessage == null)
12598
throw new RuntimeException("Menu Message can not be " + menueMessage);
12699
if (menueMessage.length() < 2) {
127100
menueMessage = new Date().toString();
128101
}
129-
try {
130-
new URL(url);// check that the URL string contains a valid URL
131-
}catch(Exception e) {
132-
// not a url
133-
BowlerStudio.runLater(()->showExceptionAlert(e,"URL does not exist: "+url));
134-
new IssueReportingExceptionHandler().except(e);
102+
if(!BowlerStudio.checkValidURL(url)) {
103+
BowlerStudio.runLater(()->BowlerStudio.showExceptionAlert(new RuntimeException(),"URL does not exist: "+url));
135104
return;
136105
}
137106
ArrayList<String> data;
@@ -152,6 +121,8 @@ public static void add(String url, String menueMessage) {
152121

153122
}
154123

124+
125+
155126
@SuppressWarnings("unchecked")
156127
public static void sort() {
157128
if (sorting)
@@ -235,6 +206,7 @@ public static void sort() {
235206
BowlerStudioMenu.setUpRepoMenue(workspaceMenu, url, false, false,
236207
arrayList.get(0));
237208
} catch (Throwable t) {
209+
System.out.println("Error with "+url+" "+arrayList.toArray());
238210
t.printStackTrace();
239211
}
240212

src/main/java/com/neuronrobotics/bowlerstudio/scripting/ScriptingFileWidget.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ private void load(ScriptingWidgetType type, File currentFile) {
274274
try {
275275
loadCodeFromFile(currentFile);
276276
} catch (IOException e1) {
277-
// TODO Auto-generated catch block
278-
e1.printStackTrace();
277+
// file has no git
278+
isOwnedByLoggedInUser=false;
279279
}
280280
// publish.setDisable(!isOwnedByLoggedInUser);
281281
runfx.setGraphic(AssetFactory.loadIcon("Run.png"));

0 commit comments

Comments
 (0)