Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 7ed8618

Browse files
committed
Fix line endings for inserted maps on Windows
Fixes https://github.com/dart-lang/yaml_edit/issues/65
1 parent 2a9a11b commit 7ed8618

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.2.1
2+
- Fix inconsistent line endings when inserting maps into a document using `\r\n`.
3+
([#65](https://github.com/dart-lang/yaml_edit/issues/65))
4+
15
## 2.2.0
26
- `AliasError` is changed to `AliasException` and exposed in the public API.
37

lib/src/strings.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ String yamlEncodeBlockString(
274274
/// Empty collections are always encoded in flow-style, so new-line must
275275
/// be avoided
276276
if (isCollection(entry.value) && !isEmpty(entry.value)) {
277-
return '$formattedKey:\n$formattedValue';
277+
return '$formattedKey:$lineEnding$formattedValue';
278278
}
279279

280280
return '$formattedKey: $formattedValue';

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: yaml_edit
2-
version: 2.2.0
2+
version: 2.2.1
33
description: A library for YAML manipulation with comment and whitespace preservation.
44
repository: https://github.com/dart-lang/yaml_edit
55
issue_tracker: https://github.com/dart-lang/yaml_edit/issues

test/windows_test.dart

+19
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,25 @@ c: 3\r
167167
expectYamlBuilderValue(doc, []);
168168
});
169169

170+
test('inserted nested map', () {
171+
final doc = YamlEditor('''
172+
a:\r
173+
b:\r
174+
''');
175+
doc.update(
176+
['a', 'b'],
177+
{
178+
'c': {'d': 'e'}
179+
},
180+
);
181+
expect(doc.toString(), equals('''
182+
a:\r
183+
b:\r
184+
c:\r
185+
d: e\r
186+
'''));
187+
});
188+
170189
test('remove from block map', () {
171190
final doc = YamlEditor('''
172191
a: 1\r

0 commit comments

Comments
 (0)