Skip to content

Commit

Permalink
Unicode Auto Detect escaping.
Browse files Browse the repository at this point in the history
Fixes Unicode format thinking a file was escaped due to
incorrect RegEx pattern.
  • Loading branch information
NBKRedSpy committed Jan 15, 2024
1 parent 27e5622 commit 31986c6
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CardSurvival-Localization/CardSurvival-Localization.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<RootNamespace>CardSurvival_Localization</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<FileVersion>3.3.0</FileVersion>
<AssemblyVersion>3.3.0</AssemblyVersion>
<FileVersion>3.3.1</FileVersion>
<AssemblyVersion>3.3.1</AssemblyVersion>
<Description></Description>
<Title></Title>
<Product>$(AssemblyName)</Product>
Expand Down
2 changes: 1 addition & 1 deletion CardSurvival-Localization/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static int Main(string[] args)
/// <returns></returns>
private static bool IsUnicodeEscaped(string json)
{
return Regex.IsMatch(json, @"u[a-f0-9]", RegexOptions.IgnoreCase);
return Regex.IsMatch(json, @"\\u[a-f0-9]", RegexOptions.IgnoreCase);
}

private static string GetErrorsAndWarnings(LocalizationKeyExtrator localizationKeyExtractor)
Expand Down
2 changes: 1 addition & 1 deletion CardSurvival-Localization/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"CardSurvival-Localization": {
"commandName": "Project",
"commandLineArgs": "\"E:\\Downloads\\Games\\Card Survival\\Raft-100-3-8-1703246519\\木筏求生\""
"commandLineArgs": "\"C:\\work\\localization\\work\""
}
}
}
68 changes: 68 additions & 0 deletions CardSurvival-LocalizationTests/ProcessModTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,74 @@ public void UnicodeEscape_AutoDetect_WithEscaped_Escaped()
Assert.Equal(expected, actual);
}


[Fact]
public void UnicodeEscape_AutoDetect_has_u_with_no_backslash_Not()
{
MockFileSystem fs = new MockFileSystem(new Dictionary<string, MockFileData>()
{
{@"x:\test\ModInfo.json", new MockFileData(@"{}") },
{@"x:\test\test.json", new MockFileData(
"""
{
'DefaultStatusName-Existing': {
'DefaultText': 'u4e00u9635u98d3u98ce',
},
'DefaultStatusName-Existing2': {
'DefaultText': '一阵飓风',
}
}
"""
)
},

}, "X:\\test");

//Reset date for check for write changes later
SetWriteTimeToMin(fs);

CardSurvival_Localization.Program.ProcessMod("X:\\test", fs, UnicodeEscapeMode.AutoDetect, true);


var expectedFiles = new List<string>()
{
@"x:\test\ModInfo.json",
"x:\\test\\test.json",
"x:\\test\\Localization\\SimpEn.psv",
"x:\\test\\Localization\\SimpEn_Errors.txt"
};

Assert.Equal<string>(fs.AllFiles.OrderBy(x => x), expectedFiles.OrderBy(x => x));

const string engPath = "x:\\test\\Localization\\SimpEn.psv";
string actual = fs.File.ReadAllText(engPath);
string expected =
"""
T-mDA3fJ+/j7ZSIYmR2spKmdU2RSs=||u4e00u9635u98d3u98ce
T-COd+NfxU19P/4TdHpGQTg4J8E/k=||一阵飓风

""";

Assert.Equal(expected, actual);

actual = fs.File.ReadAllText("x:\\test\\test.json");
expected =
"""
{
"DefaultStatusName-Existing": {
"DefaultText": "u4e00u9635u98d3u98ce",
"LocalizationKey": "T-mDA3fJ+/j7ZSIYmR2spKmdU2RSs="
},
"DefaultStatusName-Existing2": {
"DefaultText": "一阵飓风",
"LocalizationKey": "T-COd+NfxU19P/4TdHpGQTg4J8E/k="
}
}
""";

Assert.Equal(expected, actual);
}

[Fact]
public void UnicodeEscape_AutoDetect_Mixed_Escaped()
{
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This is not the CSTI-ModLoader. This utility creates an English translation fil
See the [Observations From Current Mods](#observations-from-current-mods) section.

# Video
A simple tutorial video can be found here: https://youtu.be/svdUEJXaGnY
A simple tutorial video can be found here: https://youtu.be/ABbwkaBecCg

## What Does This Utility Do?

Expand Down Expand Up @@ -154,6 +154,9 @@ https://github.com/dop-lm/CSTI-ModLoader (Currently the NoReflection branch has

# Change Log

## 3.3.1
* Corrects Unicode format Auto Detection error due to bad match string.

## 3.3.0
* Added uppercase text for escaped Unicode. By default the ModEditor will uppercase the values. This is optional via the 'u' parameter.
* This simplifies comparing the original files to the modified files.
Expand Down
5 changes: 4 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the [Observations From Current Mods](#observations-from-current-mods) sectio


[size=3][b]Video[/b][/size]
A simple tutorial video can be found here: https://youtu.be/svdUEJXaGnY
A simple tutorial video can be found here: https://youtu.be/ABbwkaBecCg

[size=3][b]What Does This Utility Do?[/b][/size]

Expand Down Expand Up @@ -185,6 +185,9 @@ https://github.com/dop-lm/CSTI-ModLoader (Currently the NoReflection branch has

[size=4][b]Change Log[/b][/size]

[size=3][b]3.3.1[/b][/size]
* Corrects Unicode format Auto Detection error due to bad match string.

[size=3][b]3.3.0[/b][/size]

* Added uppercase text for escaped Unicode. By default the ModEditor will uppercase the values. This is optional via the 'u' parameter.
Expand Down

0 comments on commit 31986c6

Please sign in to comment.