File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
src/main/java/org/scijava/plugins/scripting/python Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -118,7 +118,26 @@ public boolean isPythonMode(){
118118 }
119119
120120public void setPythonDir (final File pythonDir ){
121- this .pythonDir = pythonDir ;
121+ if (pythonDir == null ){
122+ this .pythonDir = null ;
123+ } else {
124+ // Trim whitespace and remove illegal characters from the path
125+ String path = pythonDir .getPath ();
126+ if (path != null ){
127+ // Remove leading/trailing whitespace and angle brackets
128+ path = path .trim ().replaceAll ("^[\\ s<>]+|[\\ s<>]+$" , "" );
129+ // Remove illegal characters for Windows paths except : after drive letter
130+ // Remove all colons except at index 1 (C:)
131+ if (path .length () > 2 && path .charAt (1 ) == ':' ){
132+ path = path .substring (0 , 2 ) + path .substring (2 ).replace (":" , "" );
133+ } else {
134+ path = path .replace (":" , "" );
135+ }
136+ // Remove any other illegal characters (keep it simple)
137+ path = path .replaceAll ("[\n \r \t ]" , "" );
138+ }
139+ this .pythonDir = new File (path );
140+ }
122141 }
123142
124143public void setPythonMode (final boolean pythonMode ){
@@ -257,6 +276,7 @@ private File getEnvironmentYamlFile(){
257276
258277@ Override
259278public void save (){
279+ setPythonDir (pythonDir ); // clean up the path
260280// Write python-dir and launch-mode values to app config file.
261281final String configFileProp = System .getProperty ("scijava.app.config-file" );
262282if (configFileProp == null ) return ; // No config file to update.
You can’t perform that action at this time.
0 commit comments