diff --git a/packages/pharaoh/lib/src/middleware/body_parser.dart b/packages/pharaoh/lib/src/middleware/body_parser.dart index 0b866ad7..2bb6ee39 100644 --- a/packages/pharaoh/lib/src/middleware/body_parser.dart +++ b/packages/pharaoh/lib/src/middleware/body_parser.dart @@ -51,7 +51,7 @@ bodyParser(Request req, Response res, NextFunction next) async { req.body = Uri.splitQueryString(Uri.decodeFull(body)); break; case MimeType.applicationJson: - req.body = json.decode(body); + if (body.isNotEmpty) req.body = json.decode(body); break; case MimeType.textPlain: req.body = body; diff --git a/packages/pharaoh/pubspec.yaml b/packages/pharaoh/pubspec.yaml index 06df2ec7..b2f227cf 100644 --- a/packages/pharaoh/pubspec.yaml +++ b/packages/pharaoh/pubspec.yaml @@ -1,6 +1,6 @@ name: pharaoh description: Minimalist web-server library for Dart -version: 0.0.8+1 +version: 0.0.8+2 repository: https://github.com/codekeyz/pharaoh/tree/main/packages/pharaoh environment: @@ -8,7 +8,7 @@ environment: dependencies: meta: ^1.15.0 - spanner: ^1.0.3 + spanner: ^1.0.4 mime: ^1.0.4 collection: ^1.18.0 http_parser: ^4.0.2 diff --git a/packages/spanner/lib/src/tree/tree.dart b/packages/spanner/lib/src/tree/tree.dart index 5c346ebd..96363a44 100644 --- a/packages/spanner/lib/src/tree/tree.dart +++ b/packages/spanner/lib/src/tree/tree.dart @@ -247,10 +247,15 @@ class Spanner { } final handler = rootNode.getHandler(method); + if (handler == null && wildcardNode != null) { + return RouteResult( + resolvedParams, + getResults(wildcardNode.getHandler(method)), + actual: wildcardNode, + ); + } - return handler == null - ? null - : RouteResult(resolvedParams, getResults(handler), actual: rootNode); + return RouteResult(resolvedParams, getResults(handler), actual: rootNode); } String _cleanPath(String path) { diff --git a/packages/spanner/pubspec.yaml b/packages/spanner/pubspec.yaml index af4cf7e8..6cb25a86 100644 --- a/packages/spanner/pubspec.yaml +++ b/packages/spanner/pubspec.yaml @@ -1,6 +1,6 @@ name: spanner description: Generic HTTP Router implementation, internally uses a Radix Tree (aka compact Prefix Tree), supports route params, wildcards. -version: 1.0.3 +version: 1.0.4 repository: https://github.com/Pharaoh-Framework/pharaoh/tree/main/packages/spanner environment: diff --git a/packages/spanner/test/wildcard_test.dart b/packages/spanner/test/wildcard_test.dart index 1dc4830f..b59c9a15 100644 --- a/packages/spanner/test/wildcard_test.dart +++ b/packages/spanner/test/wildcard_test.dart @@ -45,7 +45,7 @@ void main() { expect(result!.values, ['mee-moo']); result = router.lookup(HTTPMethod.POST, '/hello'); - expect(result?.values, null); + expect(result?.values, const []); }); test('static route and wildcard on same method', () {