Skip to content
Permalink
Browse files

Additional form validation + escape hatch in case GetShortPathName re…

…turns the empty string.
  • Loading branch information...
Daniel W. Barowy
Daniel W. Barowy committed Oct 31, 2016
1 parent 8779228 commit 1ad0f3c29763fcfca5e6a6801a20ed5906a187bc
Showing with 67 additions and 35 deletions.
  1. +27 −27 ExceLintCLIGenerator/Form1.Designer.cs
  2. +39 −7 ExceLintCLIGenerator/Form1.cs
  3. +1 −1 ExceLintRunner/ExceLintRunner.fsproj

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -22,6 +22,11 @@ public class InvalidJARPathException : Exception
public InvalidJARPathException(string message) : base(message) { }
}

public class CannotBeEmptyException : Exception
{
public CannotBeEmptyException(string message) : base(message) { }
}

public partial class Form1 : Form
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
@@ -38,6 +43,13 @@ private static string shortPath(string p, bool isFile)
var sb = new StringBuilder(p.Length);
GetShortPathName(p, sb, sb.Capacity);
var str = sb.ToString();

// fallback in case GetShortPathName returns the empty string
if (String.IsNullOrEmpty(str))
{
return p;
}

return str;
} else
{
@@ -219,6 +231,18 @@ private void noexitCheckBox_CheckedChanged(object sender, EventArgs e)
Properties.Settings.Default.Save();
}

private string notEmpty(string s, string fieldName)
{
var r = new System.Text.RegularExpressions.Regex("^[ ]*$");
if (r.IsMatch(s))
{
throw new CannotBeEmptyException(fieldName);
} else
{
return s;
}
}

private string[] generateCLIInvocation(bool includeEXE)
{
/*
@@ -241,13 +265,13 @@ analyzes formulas
*/
var flags = new List<string>();

if (includeEXE) flags.Add(shortPath(excelintrunnerPathTextBox.Text, isFile: true));
flags.Add(shortPath(benchmarkDirTextbox.Text, isFile: false));
flags.Add(shortPath(outputDirectoryTextbox.Text, isFile: false));
flags.Add(shortPath(excelintGroundTruthCSVTextbox.Text, isFile: true));
flags.Add(shortPath(custodesGroundTruthCSVTextbox.Text, isFile: true));
if (includeEXE) flags.Add(notEmpty(shortPath(excelintrunnerPathTextBox.Text, isFile: true), excelintRunnerEXEPathLabel.Text));
flags.Add(notEmpty(shortPath(benchmarkDirTextbox.Text, isFile: false), benchmarkDirLabel.Text));
flags.Add(notEmpty(shortPath(outputDirectoryTextbox.Text, isFile: false), outputDirecotryLabel.Text));
flags.Add(notEmpty(shortPath(excelintGroundTruthCSVTextbox.Text, isFile: true), excelintGroundTruthLabel.Text));
flags.Add(notEmpty(shortPath(custodesGroundTruthCSVTextbox.Text, isFile: true), custodesGroundTruthCSVLabel.Text));

var javaPath = shortPath(javaPathTextbox.Text, isFile: true);
var javaPath = notEmpty(shortPath(javaPathTextbox.Text, isFile: true), javaexePathLabel.Text);
if (javaPath.EndsWith("java.exe", StringComparison.InvariantCultureIgnoreCase))
{
flags.Add(javaPath);
@@ -256,7 +280,7 @@ analyzes formulas
throw new InvalidJavaEXEPathException(javaPath);
}

var jarPath = shortPath(custodesJARPathTextbox.Text, isFile: true);
var jarPath = notEmpty(shortPath(custodesJARPathTextbox.Text, isFile: true), custodesJarLabel.Text);
if (jarPath.EndsWith(".jar", StringComparison.InvariantCultureIgnoreCase))
{
flags.Add(jarPath);
@@ -306,6 +330,10 @@ private void clipboardButton_Click(object sender, EventArgs e)
{
MessageBox.Show("The following does not appear to be a valid JAR file:\n\n" + ex.Message);
}
catch (CannotBeEmptyException ex)
{
MessageBox.Show("The field '" + ex.Message + "' cannot be empty.");
}
}

public static void runCommand(string cpath, string[] args)
@@ -352,6 +380,10 @@ private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("The following does not appear to be a valid JAR file:\n\n" + ex.Message);
}
catch (CannotBeEmptyException ex)
{
MessageBox.Show("The field '" + ex.Message + "' cannot be empty.");
}
}
}
}
@@ -26,7 +26,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\Debug\ExceLintRunner.XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
<StartArguments>"C:\Users\dbarowy\Documents\Visual Studio 2015\Projects\ExceLint\data\spreadsheets\custodes" "C:\Users\dbarowy\Desktop\ETest" "C:\Users\dbarowy\Documents\Visual Studio 2015\Projects\ExceLint\data\analyses\ExceLint\ground_truth.csv" "C:\Users\dbarowy\Documents\Visual Studio 2015\Projects\ExceLint\data\analyses\CUSTODES\smell_detection_result.csv" "C:\ProgramData\Oracle\Java\javapath\java.exe" "C:\Users\dbarowy\Documents\Visual Studio 2015\Projects\ExceLint\data\analyses\CUSTODES2\cc2.jar" -verbose -spectral -css</StartArguments>
<StartArguments>C:\tmp\tstexl\custodes C:\tmp\tstexl\CUSTOD~1 C:\tmp\EXL\data\analyses\ExceLint\GROUND~1.CSV C:\tmp\EXL\data\analyses\CUSTODES\SMELL_~1.CSV C:\PROGRA~1\Java\JRE18~1.0_1\bin\java.exe C:\Users\dbarowy\DOCUME~1\VISUAL~4\Projects\ExceLint\data\analyses\CUSTOD~1\cc2.jar -thresh 5 -verbose -spectral -sheets -css</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>

0 comments on commit 1ad0f3c

Please sign in to comment.
You can’t perform that action at this time.