Skip to content

Commit

Permalink
Залечено NRE в конструкторах про которые известно. closes #1197
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilBeaver committed Nov 4, 2022
1 parent 5c04b92 commit 7744eb8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/ScriptEngine.HostedScript/Library/FixedStructureImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ private static FixedStructureImpl Constructor(StructureImpl structObject)
[ScriptConstructor(Name = "По ключам и значениям")]
public static FixedStructureImpl Constructor(IValue param1, IValue[] args)
{
var rawArgument = param1.GetRawValue();
var rawArgument = param1?.GetRawValue();
if (rawArgument == null)
return new FixedStructureImpl("");

if (rawArgument.DataType == DataType.String)
{
return new FixedStructureImpl(param1.AsString(), args);
Expand Down
5 changes: 4 additions & 1 deletion src/ScriptEngine.HostedScript/Library/StructureImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ private static StructureImpl Constructor(FixedStructureImpl fixedStruct)
[ScriptConstructor(Name = "По ключам и значениям")]
public static StructureImpl Constructor(IValue param1, IValue[] args)
{
var rawArgument = param1.GetRawValue();
var rawArgument = param1?.GetRawValue();
if (rawArgument == null)
return new StructureImpl();

if (rawArgument.DataType == DataType.String)
{
return new StructureImpl(rawArgument.AsString(), args);
Expand Down
4 changes: 2 additions & 2 deletions src/ScriptEngine.HostedScript/Library/Zip/ZipReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void Open(IValue filenameOrStream, string password = null, FileNamesEncod
{
_zip = ZipFile.Read(filenameOrStream.AsString(), new ReadOptions { Encoding = ChooseEncoding(encoding) });
}
else if (filenameOrStream.AsObject() is IStreamWrapper stream)
else if (filenameOrStream.DataType == DataType.Object && filenameOrStream.AsObject() is IStreamWrapper stream)
{
_zip = ZipFile.Read(stream.GetUnderlyingStream(), new ReadOptions { Encoding = ChooseEncoding(encoding) });
}
Expand Down Expand Up @@ -157,7 +157,7 @@ public static ZipReader Construct()
[ScriptConstructor(Name = "На основании имени файла или потока")]
public static ZipReader Constructor(IValue dataSource, IValue password = null)
{
var dataSourceRawValue = dataSource.GetRawValue();
var dataSourceRawValue = dataSource?.GetRawValue() ?? ValueFactory.CreateInvalidValueMarker();

return new ZipReader(dataSourceRawValue, password?.AsString());
}
Expand Down

0 comments on commit 7744eb8

Please sign in to comment.