diff --git a/CHANGELOG.md b/CHANGELOG.md index d732b1a..b68ae74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.2.1 +- Fix inconsistent line endings when inserting maps into a document using `\r\n`. + ([#65](https://github.com/dart-lang/yaml_edit/issues/65)) + ## 2.2.0 - `AliasError` is changed to `AliasException` and exposed in the public API. diff --git a/lib/src/strings.dart b/lib/src/strings.dart index 8767c1b..41994b9 100644 --- a/lib/src/strings.dart +++ b/lib/src/strings.dart @@ -274,7 +274,7 @@ String yamlEncodeBlockString( /// Empty collections are always encoded in flow-style, so new-line must /// be avoided if (isCollection(entry.value) && !isEmpty(entry.value)) { - return '$formattedKey:\n$formattedValue'; + return '$formattedKey:$lineEnding$formattedValue'; } return '$formattedKey: $formattedValue'; diff --git a/pubspec.yaml b/pubspec.yaml index fd13841..cea93e3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: yaml_edit -version: 2.2.0 +version: 2.2.1 description: A library for YAML manipulation with comment and whitespace preservation. repository: https://github.com/dart-lang/yaml_edit issue_tracker: https://github.com/dart-lang/yaml_edit/issues diff --git a/test/windows_test.dart b/test/windows_test.dart index a516204..50f79e7 100644 --- a/test/windows_test.dart +++ b/test/windows_test.dart @@ -167,6 +167,25 @@ c: 3\r expectYamlBuilderValue(doc, []); }); + test('inserted nested map', () { + final doc = YamlEditor(''' +a:\r + b:\r +'''); + doc.update( + ['a', 'b'], + { + 'c': {'d': 'e'} + }, + ); + expect(doc.toString(), equals(''' +a:\r + b:\r + c:\r + d: e\r +''')); + }); + test('remove from block map', () { final doc = YamlEditor(''' a: 1\r