Skip to content

Commit

Permalink
Adding testing for Process object deserializaion rule
Browse files Browse the repository at this point in the history
  • Loading branch information
mbdavid committed Dec 8, 2022
1 parent d72c677 commit 4382ff4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions LiteDB.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29609.76
# Visual Studio Version 17
VisualStudioVersion = 17.1.32328.378
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LiteDB", "LiteDB\LiteDB.csproj", "{9497DA19-1FCA-4C2E-A1AB-8DFAACBC76E1}"
EndProject
Expand Down
15 changes: 14 additions & 1 deletion LiteDB/Client/Mapper/BsonMapper.Deserialize.cs
Expand Up @@ -170,7 +170,20 @@ public object Deserialize(Type type, BsonValue value)
var actualType = _typeNameBinder.GetType(typeField.AsString);

if (actualType == null) throw LiteException.InvalidTypedName(typeField.AsString);
if (!type.IsAssignableFrom(actualType)) throw LiteException.DataTypeNotAssignable(type.FullName, actualType.FullName);

// avoid initialize class that are not assignable
if (!type.IsAssignableFrom(actualType))
{
throw LiteException.DataTypeNotAssignable(type.FullName, actualType.FullName);
}

// avoid use of "System.Diagnostics.Process" in object type definition
// using String test to work in .netstandard 1.3
if (actualType.FullName.Equals("System.Diagnostics.Process", StringComparison.OrdinalIgnoreCase) &&
actualType.Assembly.GetName().Name.Equals("System", StringComparison.OrdinalIgnoreCase))
{
throw LiteException.AvoidUseOfProcess();
}

type = actualType;
}
Expand Down
2 changes: 1 addition & 1 deletion LiteDB/LiteDB.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net45;netstandard1.3;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net4.5;netstandard1.3;netstandard2.0</TargetFrameworks>
<AssemblyVersion>5.0.12</AssemblyVersion>
<FileVersion>5.0.12</FileVersion>
<VersionPrefix>5.0.12</VersionPrefix>
Expand Down
6 changes: 6 additions & 0 deletions LiteDB/Utils/LiteException.cs
Expand Up @@ -52,6 +52,7 @@ public class LiteException : Exception
public const int INVALID_NULL_CHAR_STRING = 212;
public const int INVALID_FREE_SPACE_PAGE = 213;
public const int DATA_TYPE_NOT_ASSIGNABLE = 214;
public const int AVOID_USE_OF_PROCESS = 215;

#endregion

Expand Down Expand Up @@ -312,6 +313,11 @@ internal static LiteException DataTypeNotAssignable(string type1, string type2)
return new LiteException(DATA_TYPE_NOT_ASSIGNABLE, $"Data type {type1} is not assignable from data type {type2}");
}

internal static LiteException AvoidUseOfProcess()
{
return new LiteException(AVOID_USE_OF_PROCESS, $"LiteDB do not accept System.Diagnostics.Process class in deserialize mapper");
}

#endregion
}
}

0 comments on commit 4382ff4

Please sign in to comment.