Skip to content

Commit

Permalink
fix #441
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghuan committed Jan 6, 2024
1 parent fca1d55 commit fab5574
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CSharp.lua/CoreSystem.Lua/CoreSystem/Array.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ local function get(t, index)
if v == nil then
throw(ArgumentOutOfRangeException("index"))
end
if v ~= null then
if v ~= null then
return v
end
return nil
Expand Down
17 changes: 7 additions & 10 deletions CSharp.lua/CoreSystem.Lua/CoreSystem/Convert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,11 @@ local function fromBase64Decode(s, offset, len, t, resultLength)
local coroutine
local c = s:get(i + offset)
i = i + 1
if c >= 65 then
if c <= 90 then
c = c - 65
elseif c <= 122 then
c = c - 71
end
elseif c >= 48 then
if c >= 65 and c <= 90 then
c = c - 65
elseif c >= 97 and c <= 122 then
c = c - 71
elseif c >= 48 and c <= 57 then
c = c + 4
else
if c == 43 then
Expand Down Expand Up @@ -545,7 +543,7 @@ local function fromBase64Decode(s, offset, len, t, resultLength)
throw(FormatException("Format_BadBase64CharArrayLength"))
end

if j < 2 then
if resultLength - j < 2 then
return - 1
end

Expand All @@ -555,7 +553,7 @@ local function fromBase64Decode(s, offset, len, t, resultLength)
codes = 0x000000ff
else
while i < len - 1 do
c = s:get(i + offset)
local c = s:get(i + offset)
if c ~= 32 and c ~= 10 and c ~= 13 and c ~= 9 then
break
end
Expand Down Expand Up @@ -596,7 +594,6 @@ local function fromBase64CharPtr(s, i, n)
n = n - 1
end
local resultLength = fromBase64ComputeResultLength(s, i, n)
print(resultLength .. " xxx")
local t = {}
fromBase64Decode(s, i, n, t, resultLength)
return System.arrayFromTable(t, Byte)
Expand Down
39 changes: 38 additions & 1 deletion CSharp.lua/CoreSystem.Lua/CoreSystem/String.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,50 @@ local function checkIndex(value, startIndex, count)
return startIndex, count, len
end

-- https://stackoverflow.com/questions/7983574/how-to-write-a-unicode-symbol-in-lua
local bytemarkers = { {0x7FF,192}, {0xFFFF,224}, {0x1FFFFF,240} }
local function utf8(decimal)
if decimal < 128 then return char(decimal) end
local charbytes = {}
for i = 1, #bytemarkers do
local vals = bytemarkers[i]
if decimal<=vals[1] then
for b = i + 1, 2, -1 do
local mod = decimal%64
decimal = (decimal-mod)/64
charbytes[b] = char(128+mod)
end
charbytes[1] = char(vals[2]+decimal)
break
end
end
return tconcat(charbytes)
end

local function ctor(String, value, startIndex, count)
if type(value) == "number" then
if startIndex <= 0 then throw(ArgumentOutOfRangeException("count")) end
return rep(char(value), startIndex)
end
startIndex, count = checkIndex(value, startIndex, count)
return char(unpack(value, startIndex + 1, startIndex + count))
local found
for i = startIndex + 1, startIndex + count do
local c = value[i]
if c >= 128 then
found = true
break
end
end
if not found then
return char(unpack(value, startIndex + 1, startIndex + count))
end
local t, index = {}, 1
for i = startIndex + 1, startIndex + count do
local c = value[i]
t[index] = utf8(c)
index = index + 1
end
return tconcat(t)
end

local function get(this, index)
Expand Down
8 changes: 8 additions & 0 deletions test/BridgeNetTests/Batch1/src/BasicCSharp/TestFromIssue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ public static void TestOf458()
.ToList();
}

[Test]
public static void TestOf441()
{
var input = "aGVsbG8gd29ybGQ=";
var bytes = Convert.FromBase64String(input);
Assert.AreEqual(input, Convert.ToBase64String(bytes));
}

private class BattleModelSlotPrototype {
public string a;
public string b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Bridge.Test.NUnit;
using System;

#if false
#if true
namespace Bridge.ClientTest.ConvertTests
{
[Category(Constants.MODULE_CONVERT)]
Expand Down

0 comments on commit fab5574

Please sign in to comment.