Fix json text decode bug - thx darnn :)

This commit is contained in:
Nikolaj Olsson 2024-01-29 07:56:06 +01:00
parent 710cb31cb7
commit 5068fc65df
4 changed files with 26 additions and 2 deletions

23
src/Test/Core/JsonTest.cs Normal file
View File

@ -0,0 +1,23 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nikse.SubtitleEdit.Core.SubtitleFormats;
namespace Test.Core
{
[TestClass]
public class JsonTest
{
[TestMethod]
public void TestUnicodeFirst()
{
var result = Json.DecodeJsonText("\u05d1 ");
Assert.AreEqual("ב ", result);
}
[TestMethod]
public void TestUnicodeLast()
{
var result = Json.DecodeJsonText(" \u05d1");
Assert.AreEqual(" ב", result);
}
}
}

View File

@ -64,6 +64,7 @@
<Compile Include="Assa\ResamplerTest.cs" /> <Compile Include="Assa\ResamplerTest.cs" />
<Compile Include="Assa\AssaTimeCodes.cs" /> <Compile Include="Assa\AssaTimeCodes.cs" />
<Compile Include="Core\AudioToTextTest.cs" /> <Compile Include="Core\AudioToTextTest.cs" />
<Compile Include="Core\JsonTest.cs" />
<Compile Include="Core\MergeShortLinesUtilsTest.cs" /> <Compile Include="Core\MergeShortLinesUtilsTest.cs" />
<Compile Include="Core\CsvUtilTest.cs" /> <Compile Include="Core\CsvUtilTest.cs" />
<Compile Include="Core\WebVttHelperTest.cs" /> <Compile Include="Core\WebVttHelperTest.cs" />

View File

@ -23,7 +23,7 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
public void Initialize() public void Initialize()
{ {
_httpClient = DownloaderFactory.MakeHttpClient(); _httpClient = DownloaderFactory.MakeHttpClient();
_httpClient.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"); _httpClient.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0");
_httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=UTF-8"); _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=UTF-8");
_httpClient.BaseAddress = new Uri("https://api.mymemory.translated.net/get"); _httpClient.BaseAddress = new Uri("https://api.mymemory.translated.net/get");
} }

View File

@ -66,7 +66,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (c == '\\' && !keepNext) if (c == '\\' && !keepNext)
{ {
keepNext = true; keepNext = true;
if (i + 6 < text.Length && text[i + 1] == 'u' && if (i + 5 < text.Length && text[i + 1] == 'u' &&
hexLetters.Contains(text[i + 2]) && hexLetters.Contains(text[i + 2]) &&
hexLetters.Contains(text[i + 3]) && hexLetters.Contains(text[i + 3]) &&
hexLetters.Contains(text[i + 4]) && hexLetters.Contains(text[i + 4]) &&