Skip to content

Commit

Permalink
Enhanced compatibility with input posted from a web browser (which te…
Browse files Browse the repository at this point in the history
…nds to remove/replace the whitespace characters we need for parsing)
  • Loading branch information
c0shea committed Feb 23, 2017
1 parent 4b3120c commit 2f3941d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 54 deletions.
1 change: 0 additions & 1 deletion IdParser.Client/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ private void Main_Load(object sender, EventArgs e) {

private void btnParse_Click(object sender, EventArgs e) {
if (txtHidData.Text.Contains("@")) {
File.WriteAllText(@"C:\users\connor\desktop\parsedsdf.txt", txtHidData.Text);
ParseScanData(txtHidData.Text);
}
else {
Expand Down
30 changes: 30 additions & 0 deletions IdParser.Tests/DriversLicenseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,36 @@ public void TestCTLicense() {
}
}

[TestMethod]
public void TestCTLicenseWebBrowser() {
var barcode = @"@
AAMVA6360060101DL00290179DAACTLIC,ADULT,A
DAG60 STATE ST
DAIWETHERSFIELD
DAJCT
DAK061091896
DAQ990000001
DARD
DASB
DAT
DBA20150101
DBB19610101
DBC2
DBD20090223
DAU506
DAYBLU
DBF00
DBHY";

var idCard = IdParser.Parse(barcode, Validation.None);

Assert.IsNotNull(idCard);
Assert.AreEqual("ADULT", idCard.FirstName);
Assert.AreEqual("60 STATE ST", idCard.StreetLine1);
Assert.AreEqual("CT", idCard.JurisdictionCode);
Assert.AreEqual(new DateTime(1961, 01, 01), idCard.DateOfBirth);
}

[TestMethod]
public void TestNonStandardDataElementSeparator() {
var file = File.ReadAllText("MA License Piped.txt");
Expand Down
54 changes: 5 additions & 49 deletions IdParser.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,108 +9,64 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdParser.Tests", "IdParser.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdParser.Client", "IdParser.Client\IdParser.Client.csproj", "{FA949E77-9931-476C-BF93-DE61F5290CE7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F2E20BF1-CDBC-4A70-A551-F017A0FC6D3F}"
ProjectSection(SolutionItems) = preProject
IdParser\IdParser.nuspec = IdParser\IdParser.nuspec
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
ReleaseNET20|Any CPU = ReleaseNET20|Any CPU
ReleaseNET20|x86 = ReleaseNET20|x86
ReleaseNET35|Any CPU = ReleaseNET35|Any CPU
ReleaseNET35|x86 = ReleaseNET35|x86
ReleaseNET40|Any CPU = ReleaseNET40|Any CPU
ReleaseNET40|x86 = ReleaseNET40|x86
ReleaseNET45|Any CPU = ReleaseNET45|Any CPU
ReleaseNET45|x86 = ReleaseNET45|x86
ReleaseNET46|Any CPU = ReleaseNET46|Any CPU
ReleaseNET46|x86 = ReleaseNET46|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.Debug|Any CPU.Build.0 = Debug|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.Debug|x86.ActiveCfg = Debug|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.Debug|x86.Build.0 = Debug|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.Release|Any CPU.ActiveCfg = Release|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.Release|Any CPU.Build.0 = Release|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.Release|x86.ActiveCfg = Release|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.Release|x86.Build.0 = Release|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET20|Any CPU.ActiveCfg = ReleaseNET20|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET20|Any CPU.Build.0 = ReleaseNET20|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET20|x86.ActiveCfg = ReleaseNET20|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET20|x86.Build.0 = ReleaseNET20|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET35|Any CPU.ActiveCfg = ReleaseNET35|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET35|Any CPU.Build.0 = ReleaseNET35|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET35|x86.ActiveCfg = ReleaseNET35|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET35|x86.Build.0 = ReleaseNET35|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET40|Any CPU.ActiveCfg = ReleaseNET40|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET40|Any CPU.Build.0 = ReleaseNET40|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET40|x86.ActiveCfg = ReleaseNET40|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET40|x86.Build.0 = ReleaseNET40|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET45|Any CPU.ActiveCfg = ReleaseNET45|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET45|Any CPU.Build.0 = ReleaseNET45|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET45|x86.ActiveCfg = ReleaseNET45|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET45|x86.Build.0 = ReleaseNET45|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET46|Any CPU.ActiveCfg = ReleaseNET46|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET46|Any CPU.Build.0 = ReleaseNET46|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET46|x86.ActiveCfg = ReleaseNET46|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET46|x86.Build.0 = ReleaseNET46|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.Debug|x86.ActiveCfg = Debug|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.Debug|x86.Build.0 = Debug|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.Release|Any CPU.Build.0 = Release|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.Release|x86.ActiveCfg = Release|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.Release|x86.Build.0 = Release|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET20|Any CPU.ActiveCfg = ReleaseNET20|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET20|Any CPU.Build.0 = ReleaseNET20|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET20|x86.ActiveCfg = ReleaseNET20|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET20|x86.Build.0 = ReleaseNET20|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET35|Any CPU.ActiveCfg = ReleaseNET35|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET35|Any CPU.Build.0 = ReleaseNET35|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET35|x86.ActiveCfg = ReleaseNET35|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET35|x86.Build.0 = ReleaseNET35|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET40|Any CPU.ActiveCfg = ReleaseNET40|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET40|Any CPU.Build.0 = ReleaseNET40|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET40|x86.ActiveCfg = ReleaseNET40|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET40|x86.Build.0 = ReleaseNET40|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET45|Any CPU.ActiveCfg = ReleaseNET45|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET45|Any CPU.Build.0 = ReleaseNET45|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET45|x86.ActiveCfg = ReleaseNET45|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET45|x86.Build.0 = ReleaseNET45|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET46|Any CPU.ActiveCfg = ReleaseNET46|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET46|Any CPU.Build.0 = ReleaseNET46|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET46|x86.ActiveCfg = ReleaseNET46|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET46|x86.Build.0 = ReleaseNET46|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.Debug|x86.ActiveCfg = Debug|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.Debug|x86.Build.0 = Debug|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.Release|Any CPU.Build.0 = Release|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.Release|x86.ActiveCfg = Release|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.Release|x86.Build.0 = Release|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET20|Any CPU.ActiveCfg = ReleaseNET20|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET20|Any CPU.Build.0 = ReleaseNET20|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET20|x86.ActiveCfg = ReleaseNET20|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET20|x86.Build.0 = ReleaseNET20|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET35|Any CPU.ActiveCfg = ReleaseNET35|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET35|Any CPU.Build.0 = ReleaseNET35|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET35|x86.ActiveCfg = ReleaseNET35|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET35|x86.Build.0 = ReleaseNET35|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET40|Any CPU.ActiveCfg = ReleaseNET40|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET40|Any CPU.Build.0 = ReleaseNET40|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET40|x86.ActiveCfg = ReleaseNET40|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET40|x86.Build.0 = ReleaseNET40|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET45|Any CPU.ActiveCfg = ReleaseNET45|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET45|Any CPU.Build.0 = ReleaseNET45|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET45|x86.ActiveCfg = ReleaseNET45|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET45|x86.Build.0 = ReleaseNET45|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET46|Any CPU.ActiveCfg = ReleaseNET46|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET46|Any CPU.Build.0 = ReleaseNET46|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET46|x86.ActiveCfg = ReleaseNET46|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET46|x86.Build.0 = ReleaseNET46|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
18 changes: 17 additions & 1 deletion IdParser/IdParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public static IdentificationCard Parse(string rawPdf417Input, Validation validat
if (validationLevel == Validation.Strict) {
ValidateFormat(rawPdf417Input);
}
else {
else
{
rawPdf417Input = FixIncorrectHeader(rawPdf417Input);
rawPdf417Input = RemoveIncorrectCarriageReturns(rawPdf417Input);
}

Expand Down Expand Up @@ -108,6 +110,20 @@ private static string RemoveIncorrectCarriageReturns(string input) {
return input;
}

private static string FixIncorrectHeader(string input)
{
if (input[0] == '@' &&
input[1] == ExpectedCarriageReturn &&
input[2] == ExpectedLineFeed &&
input[3] == ExpectedRecordSeparator &&
input[4] == 'A')
{
return input.Insert(4, ExpectedCarriageReturn.ToString() + ExpectedLineFeed);
}

return input;
}

/// <summary>
/// Gets the AAMVA version of the input.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions IdParser/IdParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<AssemblyName>IdParser</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<DocumentationFile>bin\Debug\IdParser.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -20,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\IdParser.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
Expand All @@ -29,12 +31,14 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<DocumentationFile>bin\Release\IdParser.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseNET20|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Release\net20\</OutputPath>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<DefineConstants>TRACE;NET20</DefineConstants>
<DocumentationFile>bin\Release\net20\IdParser.XML</DocumentationFile>
<Optimize>true</Optimize>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -46,6 +50,7 @@
<OutputPath>bin\Release\net35\</OutputPath>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<DefineConstants>TRACE;NET35</DefineConstants>
<DocumentationFile>bin\Release\net35\IdParser.XML</DocumentationFile>
<Optimize>true</Optimize>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -57,6 +62,7 @@
<OutputPath>bin\Release\net40\</OutputPath>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<DefineConstants>TRACE;NET40</DefineConstants>
<DocumentationFile>bin\Release\net40\IdParser.XML</DocumentationFile>
<Optimize>true</Optimize>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -68,6 +74,7 @@
<OutputPath>bin\Release\net45\</OutputPath>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<DefineConstants>TRACE;NET45</DefineConstants>
<DocumentationFile>bin\Release\net45\IdParser.XML</DocumentationFile>
<Optimize>true</Optimize>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -79,6 +86,7 @@
<OutputPath>bin\Release\net46\</OutputPath>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<DefineConstants>TRACE;NET46</DefineConstants>
<DocumentationFile>bin\Release\net46\IdParser.XML</DocumentationFile>
<Optimize>true</Optimize>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
6 changes: 3 additions & 3 deletions IdParser/IdParser.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>IdParser</id>
<version>2.0.1</version>
<version>2.1.0</version>
<title>ID Parser</title>
<authors>Connor O'Shea</authors>
<owners>Connor O'Shea</owners>
Expand All @@ -11,8 +11,8 @@
<iconUrl>https://raw.githubusercontent.com/c0shea/IdParser/master/NuGet%20Package%20Icon.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Parses AAMVA-compliant driver's licenses and ID cards</description>
<releaseNotes>Fixed a bug in removing incorrect line endings and added .NET 2.0 assembly to package.</releaseNotes>
<copyright>Copyright 2016</copyright>
<releaseNotes>Enhanced compatibility with web browsers.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>Drivers License Identification Parser PDF417 AAMVA</tags>
</metadata>
<files>
Expand Down

0 comments on commit 2f3941d

Please sign in to comment.