Skip to content

Dev 2303 #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions sdk/Domain/OssResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/Domain/PolicyConditions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public override string Jsonize()
switch (TupleType)
{
case TupleType.Two:
jsonizedCond = String.Format("{{\"{0}\":\"{1}\"}},", Name, Value);
jsonizedCond = String.Format("{{\"{0}\":\"{1}\"}},", Util.HttpUtils.JsonEscapeString(Name), Util.HttpUtils.JsonEscapeString(Value));
break;
case TupleType.Three:
jsonizedCond = String.Format("[\"eq\",\"${0}\",\"{1}\"],", Name, Value);
jsonizedCond = String.Format("[\"eq\",\"${0}\",\"{1}\"],", Util.HttpUtils.JsonEscapeString(Name), Util.HttpUtils.JsonEscapeString(Value));
break;
default:
throw new InvalidEnumArgumentException("Invalid tuple type " + TupleType.ToString());
Expand All @@ -116,7 +116,7 @@ public StartWithConditionItem(string name, string value)

public override string Jsonize()
{
return String.Format("[\"starts-with\",\"${0}\",\"{1}\"],", Name, Value);
return String.Format("[\"starts-with\",\"${0}\",\"{1}\"],", Util.HttpUtils.JsonEscapeString(Name), Util.HttpUtils.JsonEscapeString(Value));
}
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/Domain/RestoreObjectRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Aliyun.OSS
public class RestoreObjectRequest
{
private int _day = 1;
private TierType _tierType = TierType.Standard;
private TierType? _tierType = TierType.Standard;
private bool _defaultParameter = true;

/// <summary>
Expand Down Expand Up @@ -44,7 +44,7 @@ public int Days
/// <summary>
/// Gets or sets the TierType
/// </summary>
public TierType Tier
public TierType? Tier
{
get { return _tierType; }
set { _tierType = value; _defaultParameter = false; }
Expand Down
38 changes: 19 additions & 19 deletions sdk/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions sdk/Transform/RestoreObjectRequestSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public override Stream Serialize(RestoreObjectRequest request)
{
var model = new RestoreRequestModel();
model.Days = request.Days;
model.JobParameter = new RestoreRequestModel.JobParameters();
model.JobParameter.Tier = request.Tier;
if (request.Tier != null) {
model.JobParameter = new RestoreRequestModel.JobParameters();
model.JobParameter.Tier = request.Tier.Value;
}
return ContentSerializer.Serialize(model);
}
}
Expand Down
70 changes: 68 additions & 2 deletions sdk/Util/HttpUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,80 @@ public static string GetContentType(string key, string file)
{
}

#if !NETCOREAPP2_0
var contentType = System.Web.MimeMapping.GetMimeMapping(fileType);
if (!string.IsNullOrEmpty(contentType))
{
return contentType;
}
#else
fileType = fileType.Trim().TrimStart(new char[1] { '.' }).ToLower();

if (_mimeDict.ContainsKey(fileType))
{
return _mimeDict[fileType];
}

#endif
return DefaultContentType;
}

public static string JsonEscapeString(string src)
{
if (src == null)
return null;

for (int i = 0; i < src.Length; i++)
if (JsonNeedEscape(src, i))
{
var sb = new StringBuilder();
if (i > 0)
sb.Append(src, 0, i);
return JsonDoEscapeString(sb, src, i);
}
return src;
}

internal static bool JsonNeedEscape(string src, int i)
{
char c = src[i];
return c < 32 || c == '"' || c == '\\'
// Broken lead surrogate
|| (c >= '\uD800' && c <= '\uDBFF' &&
(i == src.Length - 1 || src[i + 1] < '\uDC00' || src[i + 1] > '\uDFFF'))
// Broken tail surrogate
|| (c >= '\uDC00' && c <= '\uDFFF' &&
(i == 0 || src[i - 1] < '\uD800' || src[i - 1] > '\uDBFF'))
// To produce valid JavaScript
|| c == '\u2028' || c == '\u2029'
// Escape "</" for <script> tags
|| (c == '/' && i > 0 && src[i - 1] == '<');
}

internal static string JsonDoEscapeString(StringBuilder sb, string src, int cur)
{
int start = cur;
for (int i = cur; i < src.Length; i++)
if (JsonNeedEscape(src, i))
{
sb.Append(src, start, i - start);
switch (src[i])
{
case '\b': sb.Append("\\b"); break;
case '\f': sb.Append("\\f"); break;
case '\n': sb.Append("\\n"); break;
case '\r': sb.Append("\\r"); break;
case '\t': sb.Append("\\t"); break;
case '\"': sb.Append("\\\""); break;
case '\\': sb.Append("\\\\"); break;
case '/': sb.Append("\\/"); break;
default:
sb.Append("\\u");
sb.Append(((int)src[i]).ToString("x04"));
break;
}
start = i + 1;
}
sb.Append(src, start, src.Length - start);
return sb.ToString();
}
}
}
7 changes: 5 additions & 2 deletions sdk/aliyun-oss-sdk.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{67BDC800-084C-4F84-8A80-661B5AFE499A}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<RootNamespace>Aliyun.OSS</RootNamespace>
<AssemblyName>Aliyun.OSS</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<AppDesignerFolder>Properties</AppDesignerFolder>
Expand Down Expand Up @@ -126,6 +126,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
Expand All @@ -135,12 +136,14 @@
<DebugSymbols>true</DebugSymbols>
<RunCodeAnalysis>true</RunCodeAnalysis>
<DocumentationFile>bin\Release\Aliyun.OSS.XML</DocumentationFile>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>aliyun_sdk_net.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
Expand Down
Loading