Skip to content

Commit

Permalink
Fix line endings for inserted maps on Windows (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTup authored Feb 21, 2024
1 parent 6906ac4 commit 82ab64d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 2.2.0

- Fix inconsistent line endings when inserting maps into a document using `\r\n`.
([#65](https://github.com/dart-lang/yaml_edit/issues/65))

- `AliasError` is changed to `AliasException` and exposed in the public API.

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

## 2.1.0

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

## 2.0.3

- Updated the value of the pubspec `repository` field.

## 2.0.2

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

## 2.0.1

- License changed to BSD, as this package is now maintained by the Dart team.
- Fixed minor lints.

## 2.0.0

- Migrated to null-safety.
- API will no-longer return `null` in-place of a `YamlNode`, instead a
`YamlNode` with `YamlNode.value == null` should be used. These are easily
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
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 82ab64d

Please sign in to comment.