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

Fix line endings for inserted maps on Windows #66

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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