Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚑️ Fix type promotions for the UTF-8 encoder #2185

Merged
merged 3 commits into from
Apr 14, 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
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
Loading