From 7744eb8886be9e0c81be644c895dc607d6dc8912 Mon Sep 17 00:00:00 2001 From: EvilBeaver Date: Fri, 4 Nov 2022 15:06:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BB=D0=B5=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=20NRE=20=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80?= =?UTF-8?q?=D1=83=D0=BA=D1=82=D0=BE=D1=80=D0=B0=D1=85=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B5=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=B2=D0=B5=D1=81=D1=82=D0=BD=D0=BE.=20closes=20#1197?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ScriptEngine.HostedScript/Library/FixedStructureImpl.cs | 5 ++++- src/ScriptEngine.HostedScript/Library/StructureImpl.cs | 5 ++++- src/ScriptEngine.HostedScript/Library/Zip/ZipReader.cs | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ScriptEngine.HostedScript/Library/FixedStructureImpl.cs b/src/ScriptEngine.HostedScript/Library/FixedStructureImpl.cs index 45e601828..c0b55fce7 100644 --- a/src/ScriptEngine.HostedScript/Library/FixedStructureImpl.cs +++ b/src/ScriptEngine.HostedScript/Library/FixedStructureImpl.cs @@ -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); diff --git a/src/ScriptEngine.HostedScript/Library/StructureImpl.cs b/src/ScriptEngine.HostedScript/Library/StructureImpl.cs index 432e75c0c..bcdd04edc 100644 --- a/src/ScriptEngine.HostedScript/Library/StructureImpl.cs +++ b/src/ScriptEngine.HostedScript/Library/StructureImpl.cs @@ -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); diff --git a/src/ScriptEngine.HostedScript/Library/Zip/ZipReader.cs b/src/ScriptEngine.HostedScript/Library/Zip/ZipReader.cs index f297c8fc7..29f06582e 100644 --- a/src/ScriptEngine.HostedScript/Library/Zip/ZipReader.cs +++ b/src/ScriptEngine.HostedScript/Library/Zip/ZipReader.cs @@ -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) }); } @@ -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()); }