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

Commit 82ab64d

Browse files
authored
Fix line endings for inserted maps on Windows (#66)
Fixes https://github.com/dart-lang/yaml_edit/issues/65
1 parent 6906ac4 commit 82ab64d

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

CHANGELOG.md

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

48
All node-mutating methods on `YamlEditor`, i.e. `update()`, `appendToList()`,
@@ -13,6 +17,7 @@
1317
- Require Dart 2.19
1418

1519
## 2.1.0
20+
1621
- **Breaking** `wrapAsYamlNode(value, collectionStyle, scalarStyle)` will apply
1722
`collectionStyle` and `scalarStyle` recursively when wrapping a children of
1823
`Map` and `List`.
@@ -26,18 +31,22 @@
2631
([#23](https://github.com/dart-lang/yaml_edit/issues/23))
2732

2833
## 2.0.3
34+
2935
- Updated the value of the pubspec `repository` field.
3036

3137
## 2.0.2
38+
3239
- Fix trailing whitespace after adding new key with block-value to map
3340
([#15](https://github.com/dart-lang/yaml_edit/issues/15)).
3441
- Updated `repository` and other meta-data in `pubspec.yaml`.
3542

3643
## 2.0.1
44+
3745
- License changed to BSD, as this package is now maintained by the Dart team.
3846
- Fixed minor lints.
3947

4048
## 2.0.0
49+
4150
- Migrated to null-safety.
4251
- API will no-longer return `null` in-place of a `YamlNode`, instead a
4352
`YamlNode` with `YamlNode.value == null` should be used. These are easily

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';

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)