Skip to content

Commit c03ea26

Browse files
authored
bugfix: Use wildcard when no terminal (#135)
* _ * _ * bump package versions * _ * _
1 parent 20ebde4 commit c03ea26

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

packages/pharaoh/lib/src/middleware/body_parser.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bodyParser(Request req, Response res, NextFunction next) async {
5151
req.body = Uri.splitQueryString(Uri.decodeFull(body));
5252
break;
5353
case MimeType.applicationJson:
54-
req.body = json.decode(body);
54+
if (body.isNotEmpty) req.body = json.decode(body);
5555
break;
5656
case MimeType.textPlain:
5757
req.body = body;

packages/pharaoh/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: pharaoh
22
description: Minimalist web-server library for Dart
3-
version: 0.0.8+1
3+
version: 0.0.8+2
44
repository: https://github.com/codekeyz/pharaoh/tree/main/packages/pharaoh
55

66
environment:
77
sdk: ^3.0.0
88

99
dependencies:
1010
meta: ^1.15.0
11-
spanner: ^1.0.3
11+
spanner: ^1.0.4
1212
mime: ^1.0.4
1313
collection: ^1.18.0
1414
http_parser: ^4.0.2

packages/spanner/lib/src/tree/tree.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,15 @@ class Spanner {
247247
}
248248

249249
final handler = rootNode.getHandler(method);
250+
if (handler == null && wildcardNode != null) {
251+
return RouteResult(
252+
resolvedParams,
253+
getResults(wildcardNode.getHandler(method)),
254+
actual: wildcardNode,
255+
);
256+
}
250257

251-
return handler == null
252-
? null
253-
: RouteResult(resolvedParams, getResults(handler), actual: rootNode);
258+
return RouteResult(resolvedParams, getResults(handler), actual: rootNode);
254259
}
255260

256261
String _cleanPath(String path) {

packages/spanner/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: spanner
22
description: Generic HTTP Router implementation, internally uses a Radix Tree (aka compact Prefix Tree), supports route params, wildcards.
3-
version: 1.0.3
3+
version: 1.0.4
44
repository: https://github.com/Pharaoh-Framework/pharaoh/tree/main/packages/spanner
55

66
environment:

packages/spanner/test/wildcard_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void main() {
4545
expect(result!.values, ['mee-moo']);
4646

4747
result = router.lookup(HTTPMethod.POST, '/hello');
48-
expect(result?.values, null);
48+
expect(result?.values, const []);
4949
});
5050

5151
test('static route and wildcard on same method', () {

0 commit comments

Comments
 (0)