Skip to content

Commit

Permalink
🔖 release v8.0.2 (#637)
Browse files Browse the repository at this point in the history
- 🐛 properly escape single quote in cURL interceptor output #635
- 🎨 remove duplicate null-coalescing responseTypeReference #634
  • Loading branch information
techouse authored Sep 5, 2024
1 parent d3d468e commit b58a090
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 32 deletions.
4 changes: 4 additions & 0 deletions chopper/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 8.0.2

- Properly escape single quote in cURL interceptor output ([#635](https://github.com/lejard-h/chopper/pull/635))

## 8.0.1+1

- Re-remove internal `qs.ListFormat` wrapper
Expand Down
4 changes: 2 additions & 2 deletions chopper/lib/src/interceptors/curl_interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CurlInterceptor implements Interceptor {
if (baseRequest is http.Request) {
final String body = baseRequest.body;
if (body.isNotEmpty) {
curlParts.add("-d '$body'");
curlParts.add("-d '${body.replaceAll("'", r"'\''")}'");
}
}
if (baseRequest is http.MultipartRequest) {
Expand All @@ -36,7 +36,7 @@ class CurlInterceptor implements Interceptor {
curlParts.add("-f '${file.field}: ${file.filename ?? ''}'");
}
}
curlParts.add('"${baseRequest.url}"');
curlParts.add("'${baseRequest.url}'");
chopperLogger.info(curlParts.join(' '));

return chain.proceed(chain.request);
Expand Down
6 changes: 3 additions & 3 deletions chopper/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: chopper
description: Chopper is an http client generator using source_gen, inspired by Retrofit
version: 8.0.1+1
version: 8.0.2
documentation: https://hadrien-lejard.gitbook.io/chopper
repository: https://github.com/lejard-h/chopper

Expand All @@ -12,7 +12,7 @@ dependencies:
http: ^1.1.0
logging: ^1.2.0
meta: ^1.9.1
qs_dart: ^1.2.0
qs_dart: ^1.2.3

dev_dependencies:
build_runner: ^2.4.9
Expand All @@ -26,7 +26,7 @@ dev_dependencies:
lints: ^4.0.0
test: ^1.25.5
transparent_image: ^2.0.1
chopper_generator: ^8.0.0
chopper_generator: ^8.0.1

dependency_overrides:
chopper_generator:
Expand Down
67 changes: 44 additions & 23 deletions chopper/test/interceptors_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ void main() {
);
});

final fakeRequest = Request(
'POST',
Uri.parse('/'),
Uri.parse('base'),
body: 'test',
headers: {'foo': 'bar'},
);

test('Curl interceptors', () async {
final fakeRequest = Request(
'POST',
Uri.parse('/'),
Uri.parse('base'),
body: 'test',
headers: {'foo': 'bar'},
);

final curl = CurlInterceptor();
var log = '';
chopperLogger.onRecord.listen((r) => log = r.message);
Expand All @@ -108,27 +108,48 @@ void main() {
expect(
log,
equals(
"curl -v -X POST -H 'foo: bar' -H 'content-type: text/plain; charset=utf-8' -d 'test' \"base/\"",
r"curl -v -X POST -H 'foo: bar' -H 'content-type: text/plain; charset=utf-8' -d 'test' 'base/'",
),
);
});

final fakeRequestMultipart = Request(
'POST',
Uri.parse('/'),
Uri.parse('base'),
headers: {'foo': 'bar'},
parts: [
PartValue<int>('p1', 123),
PartValueFile<http.MultipartFile>(
'p2',
http.MultipartFile.fromBytes('file', [0], filename: 'filename'),
test('Curl interceptor with escaped text', () async {
final fakeRequest = Request(
'POST',
Uri.parse('/'),
Uri.parse('base'),
body: r"""Lorem's ipsum "dolor" sit amet""",
);

final curl = CurlInterceptor();
var log = '';
chopperLogger.onRecord.listen((r) => log = r.message);
await curl.intercept(FakeChain(fakeRequest));

expect(
log,
equals(
r"""curl -v -X POST -H 'content-type: text/plain; charset=utf-8' -d 'Lorem'\''s ipsum "dolor" sit amet' 'base/'""",
),
],
multipart: true,
);
);
});

test('Curl interceptors Multipart', () async {
final fakeRequestMultipart = Request(
'POST',
Uri.parse('/'),
Uri.parse('base'),
headers: {'foo': 'bar'},
parts: [
PartValue<int>('p1', 123),
PartValueFile<http.MultipartFile>(
'p2',
http.MultipartFile.fromBytes('file', [0], filename: 'filename'),
),
],
multipart: true,
);

final curl = CurlInterceptor();
var log = '';
chopperLogger.onRecord.listen((r) => log = r.message);
Expand All @@ -137,7 +158,7 @@ void main() {
expect(
log,
equals(
"curl -v -X POST -H 'foo: bar' -f 'p1: 123' -f 'file: filename' \"base/\"",
r"curl -v -X POST -H 'foo: bar' -f 'p1: 123' -f 'file: filename' 'base/'",
),
);
});
Expand Down
4 changes: 4 additions & 0 deletions chopper_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 8.0.2

- Remove duplicate null-coalescing `responseTypeReference` ([#634](https://github.com/lejard-h/chopper/pull/634))

## 8.0.1

- Directly export `qs.ListFormat` instead of internal wrapper ([#624](https://github.com/lejard-h/chopper/pull/624))
Expand Down
5 changes: 2 additions & 3 deletions chopper_generator/lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,8 @@ final class ChopperGenerator

// Set Response with generic types
final Reference responseTypeReference = refer(
responseType?.getDisplayString(withNullability: false) ??
responseType?.getDisplayString(withNullability: false) ??
'dynamic');
responseType?.getDisplayString(withNullability: false) ?? 'dynamic',
);
// Set the return type
final returnType = isResponseObject
? refer(m.returnType.getDisplayString(withNullability: false))
Expand Down
2 changes: 1 addition & 1 deletion chopper_generator/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: chopper_generator
description: Chopper is an http client generator using source_gen, inspired by Retrofit
version: 8.0.1
version: 8.0.2
documentation: https://hadrien-lejard.gitbook.io/chopper
repository: https://github.com/lejard-h/chopper

Expand Down

0 comments on commit b58a090

Please sign in to comment.