Skip to content

Commit

Permalink
Fix line endings for inserted maps on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTup committed Feb 20, 2024
1 parent 2a9a11b commit 7ed8618
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion lib/src/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/windows_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7ed8618

Please # to comment.