Skip to content

Commit

Permalink
fix: End-of-lines in YAML serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljankowski-columbus committed Mar 26, 2024
1 parent 74c8e6e commit e04966e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ internal interface IConfigurationRepository

internal abstract class ConfigurationRepository : IConfigurationRepository
{
private readonly string _eol;
protected readonly string Eol;

protected ConfigurationRepository(ToolInternalOptions options)
{
_eol = ResolveEndOfLine(options);
Eol = ResolveEndOfLine(options);
}

public abstract IReadOnlyDictionary<string, object>[] Load(Stream stream);
Expand All @@ -30,11 +30,11 @@ protected string Serialize(IEnumerable<IReadOnlyDictionary<string, object>> sett
{
var serialized = settings.Select(setting => $" {JsonConvert.SerializeObject(setting)}");

var separator = $",{_eol}";
var separator = $",{Eol}";
var formatted = string.Join(separator, serialized)
.BeautifyJson();

return $"[{_eol}{formatted}{_eol}]";
return $"[{Eol}{formatted}{Eol}]";
}

protected static IReadOnlyDictionary<string, object>[] Deserialize(string settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ public override void Save(Stream stream, IEnumerable<IReadOnlyDictionary<string,
}
};

var yaml = _serializer.Serialize(root);
yaml = yaml.Replace(Environment.NewLine, Eol);

var writer = new StreamWriter(stream);
_serializer.Serialize(writer, root);
writer.Write(yaml);
writer.Flush();
}
}

0 comments on commit e04966e

Please sign in to comment.