Skip to content

Commit

Permalink
🚑️ Fix type promotions for the UTF-8 encoder (#2185)
Browse files Browse the repository at this point in the history
Fixes #2184
  • Loading branch information
AlexV525 authored Apr 14, 2024
1 parent b662732 commit 8484e9a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ jobs:
run: melos run test:web:firefox
- name: '[Verify step] Test Flutter packages'
run: melos run test:flutter
- name: '[Verify step] Build Flutter APK'
run: melos run build:example:apk
# Coverage
- name: '[Coverage] Format & print test coverage'
if: ${{ matrix.sdk == 'stable' }}
Expand Down
2 changes: 1 addition & 1 deletion dio/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ See the [Migration Guide][] for the complete breaking changes list.**

## Unreleased

*None.*
- Fix type promotions for the UTF-8 encoder on previous Dart SDKs.

## 5.4.3

Expand Down
20 changes: 13 additions & 7 deletions dio/lib/src/form_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,32 @@ class FormData {
_isFinalized = true;

final controller = StreamController<Uint8List>(sync: false);
void writeAscii(String s) => controller.add(utf8.encode(s));
void writeUtf8(String string) => controller.add(utf8.encode(string));

void writeUtf8(String s) {
final encoded = utf8.encode(s);
controller.add(
encoded is Uint8List ? encoded : Uint8List.fromList(encoded),
);
}

void writeLine() => controller.add(_rnU8); // \r\n

for (final entry in fields) {
writeAscii('--$boundary$_rn');
writeAscii(_headerForField(entry.key, entry.value));
writeUtf8('--$boundary$_rn');
writeUtf8(_headerForField(entry.key, entry.value));
writeUtf8(entry.value);
writeLine();
}

Future<void>(() async {
for (final file in files) {
writeAscii('--$boundary$_rn');
writeAscii(_headerForFile(file));
writeUtf8('--$boundary$_rn');
writeUtf8(_headerForFile(file));
await writeStreamToSink(file.value.finalize(), controller);
writeLine();
}
}).then((_) {
writeAscii('--$boundary--$_rn');
writeUtf8('--$boundary--$_rn');
}).whenComplete(() {
controller.close();
});
Expand Down
7 changes: 7 additions & 0 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ scripts:
httpbun:com:
description: Run httpbun locally
run: echo "const httpbunBaseUrl = 'https://httpbun.com';" > dio_test/lib/src/httpbun.dart

test:
name: All tests
run: |
Expand Down Expand Up @@ -120,6 +121,12 @@ scripts:
melos run test
melos run coverage:format
melos run coverage:show
build:example:apk:
run: |
cd example_flutter_app
flutter build apk --debug
coverage:format:
name: Format coverage
run: |
Expand Down

0 comments on commit 8484e9a

Please sign in to comment.