Skip to content
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

Fix "null" strings on writing yaml files #576

Merged
merged 2 commits into from
Jan 4, 2023
Merged
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
2 changes: 1 addition & 1 deletion OpenUtau.Core/OpenUtau.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PackageReference Include="TinyPinyin.Net" Version="1.0.2" />
<PackageReference Include="UTF.Unknown" Version="2.5.1" />
<PackageReference Include="WanaKana-net" Version="1.0.0" />
<PackageReference Include="YamlDotNet" Version="11.2.1" />
<PackageReference Include="YamlDotNet" Version="12.0.1" />
<PackageReference Include="NetMQ" Version="4.0.1.9" />
</ItemGroup>
<ItemGroup Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">
Expand Down
1 change: 1 addition & 0 deletions OpenUtau.Core/Util/Yaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static class Yaml {
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull)
.WithEventEmitter(next => new FlowEmitter(next))
.DisableAliases()
.WithQuotingNecessaryStrings()
.Build();

public static IDeserializer DefaultDeserializer = new DeserializerBuilder()
Expand Down
15 changes: 8 additions & 7 deletions OpenUtau.Test/Classic/VoicebankConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,36 @@ public void SerializationTest() {
var yaml = Yaml.DefaultSerializer.Serialize(CreateConfig());
output.WriteLine(yaml);

//"" evaluates to " in verbatim string literals
Assert.Equal(@"portrait_opacity: 0.75
symbol_set:
preset: hiragana
head: '-'
tail: R
subbanks:
- prefix: ''
suffix: ''
- prefix: """"
suffix: """"
tone_ranges:
- C1-C4
- prefix: ''
- prefix: """"
suffix: D4
tone_ranges:
- C#4-F4
- prefix: ''
- prefix: """"
suffix: G4
tone_ranges:
- F#4-A#4
- prefix: ''
- prefix: """"
suffix: C5
tone_ranges:
- B4-B7
- color: power
prefix: ''
prefix: """"
suffix: C5P
tone_ranges:
- B4-B7
- color: shout
prefix: ''
prefix: """"
suffix: C5S
tone_ranges:
- B4-B7
Expand Down
8 changes: 8 additions & 0 deletions OpenUtau.Test/Core/USTx/UstxYamlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ public void SpecialLyric() {
yaml = Yaml.DefaultSerializer.Serialize(new UNote() { lyric = "-&" });
actual = Yaml.DefaultDeserializer.Deserialize<UNote>(yaml);
Assert.Equal("-&", actual.lyric);

yaml = Yaml.DefaultSerializer.Serialize(new UNote() { lyric = "null" });
actual = Yaml.DefaultDeserializer.Deserialize<UNote>(yaml);
Assert.Equal("null", actual.lyric);

yaml = Yaml.DefaultSerializer.Serialize(new UNote() { lyric = "true" });
actual = Yaml.DefaultDeserializer.Deserialize<UNote>(yaml);
Assert.Equal("true", actual.lyric);
}
}
}