Skip to content

Commit

Permalink
bugfix: Use wildcard when no terminal (#135)
Browse files Browse the repository at this point in the history
* _

* _

* bump package versions

* _

* _
  • Loading branch information
codekeyz authored Nov 5, 2024
1 parent 20ebde4 commit c03ea26
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/pharaoh/lib/src/middleware/body_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/pharaoh/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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:
sdk: ^3.0.0

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
Expand Down
11 changes: 8 additions & 3 deletions packages/spanner/lib/src/tree/tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/spanner/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/spanner/test/wildcard_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down

0 comments on commit c03ea26

Please sign in to comment.