mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +08:00
Bug fix curl_parser
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
## 0.1.3
|
||||||
|
|
||||||
|
- Bugfix: Header with `:` in value gets parsed properly
|
||||||
|
|
||||||
## 0.1.2
|
## 0.1.2
|
||||||
|
|
||||||
- Bump dependencies.
|
- Bump dependencies.
|
||||||
|
|||||||
@@ -130,10 +130,15 @@ class Curl extends Equatable {
|
|||||||
headers = <String, String>{};
|
headers = <String, String>{};
|
||||||
for (var headerString in headersList) {
|
for (var headerString in headersList) {
|
||||||
final splittedHeaderString = headerString.split(RegExp(r':\s*'));
|
final splittedHeaderString = headerString.split(RegExp(r':\s*'));
|
||||||
if (splittedHeaderString.length != 2) {
|
if (splittedHeaderString.length > 2) {
|
||||||
|
headers.addAll({
|
||||||
|
splittedHeaderString[0]: splittedHeaderString.sublist(1).join(":")
|
||||||
|
});
|
||||||
|
} else if (splittedHeaderString.length < 2) {
|
||||||
throw Exception('Failed to split the `$headerString` header');
|
throw Exception('Failed to split the `$headerString` header');
|
||||||
|
} else {
|
||||||
|
headers.addAll({splittedHeaderString[0]: splittedHeaderString[1]});
|
||||||
}
|
}
|
||||||
headers.addAll({splittedHeaderString[0]: splittedHeaderString[1]});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
name: curl_parser
|
name: curl_parser
|
||||||
description: Parse cURL command to Dart object and convert Dart object to cURL command.
|
description: Parse cURL command to Dart object and convert Dart object to cURL command.
|
||||||
version: 0.1.2
|
version: 0.1.3
|
||||||
homepage: https://github.com/foss42/apidash/tree/main/packages/curl_parser
|
homepage: https://github.com/foss42/apidash/tree/main/packages/curl_parser
|
||||||
repository: https://github.com/foss42/apidash/tree/main/packages/curl_parser
|
repository: https://github.com/foss42/apidash/tree/main/packages/curl_parser
|
||||||
issue_tracker: https://github.com/foss42/apidash/issues
|
issue_tracker: https://github.com/foss42/apidash/issues
|
||||||
|
|||||||
@@ -19,6 +19,30 @@ void main() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'parse another easy cURL',
|
||||||
|
() async {
|
||||||
|
expect(
|
||||||
|
Curl.parse(
|
||||||
|
r"""curl --location --request GET 'https://dummyimage.com/150/92c952' \
|
||||||
|
--header 'user-agent: Dart/3.8 (dart:io)' \
|
||||||
|
--header 'accept-encoding: gzip' \
|
||||||
|
--header 'content-length: 0' \
|
||||||
|
--header 'host: dummyimage.com'"""),
|
||||||
|
Curl(
|
||||||
|
method: 'GET',
|
||||||
|
uri: Uri.parse('https://dummyimage.com/150/92c952'),
|
||||||
|
headers: {
|
||||||
|
'user-agent': 'Dart/3.8 (dart:io)',
|
||||||
|
'accept-encoding': 'gzip',
|
||||||
|
'content-length': '0',
|
||||||
|
'host': 'dummyimage.com'
|
||||||
|
},
|
||||||
|
location: true),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('parse POST request with multipart/form-data', () {
|
test('parse POST request with multipart/form-data', () {
|
||||||
const curl = r'''curl -X POST 'https://api.apidash.dev/io/img' \
|
const curl = r'''curl -X POST 'https://api.apidash.dev/io/img' \
|
||||||
-H 'Content-Type: multipart/form-data' \
|
-H 'Content-Type: multipart/form-data' \
|
||||||
|
|||||||
@@ -32,6 +32,30 @@ void main() {
|
|||||||
);
|
);
|
||||||
}, timeout: defaultTimeout);
|
}, timeout: defaultTimeout);
|
||||||
|
|
||||||
|
test('parse cURL DevTools', () async {
|
||||||
|
expect(
|
||||||
|
splitAsCommandLineArgs(
|
||||||
|
r"""--request GET 'https://dummyimage.com/150/92c952' \
|
||||||
|
--header 'user-agent: Dart/3.8 (dart:io)' \
|
||||||
|
--header 'accept-encoding: gzip' \
|
||||||
|
--header 'content-length: 0' \
|
||||||
|
--header 'host: dummyimage.com'"""),
|
||||||
|
[
|
||||||
|
'--request',
|
||||||
|
'GET',
|
||||||
|
'https://dummyimage.com/150/92c952',
|
||||||
|
'--header',
|
||||||
|
'user-agent: Dart/3.8 (dart:io)',
|
||||||
|
'--header',
|
||||||
|
'accept-encoding: gzip',
|
||||||
|
'--header',
|
||||||
|
'content-length: 0',
|
||||||
|
'--header',
|
||||||
|
'host: dummyimage.com'
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}, timeout: defaultTimeout);
|
||||||
|
|
||||||
test('parse cURL with body', () async {
|
test('parse cURL with body', () async {
|
||||||
expect(
|
expect(
|
||||||
splitAsCommandLineArgs(r"""--request POST \
|
splitAsCommandLineArgs(r"""--request POST \
|
||||||
|
|||||||
Reference in New Issue
Block a user