Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/src/extensions/string_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@ extension PathNormalizer on String {
}
return changed ? String.fromCharCodes(codes) : this;
}

String decodeUriWithoutSlash() {
List<String> parts = split('%2F');
List<String> decodedParts =
parts.map((part) => Uri.decodeComponent(part)).toList();
return decodedParts.join('%2F');
}
}
2 changes: 1 addition & 1 deletion lib/src/route_matcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class RouteMatcher {
String input, List<HttpRoute> options, Method method) sync* {
// decode URL path before matching except for "/"
final inputPath =
Uri.parse(input).path.normalizePath.decodeUri(DecodeMode.AllButSlash);
Uri.parse(input).path.normalizePath.decodeUriWithoutSlash();

for (final option in options) {
// Check if http method matches
Expand Down
9 changes: 8 additions & 1 deletion test/route_matcher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ void main() {
hexRoute,
genericRoute
]);
expect(routes(match('/xxx/%3123/test', testRoutes)), // %31 is character "1"
expect(
routes(match('/xxx/%3123/test', testRoutes)), // %31 is character "1"
[
patternRoute,
intRoute,
Expand Down Expand Up @@ -208,6 +209,12 @@ void main() {
{'value': 'input', 'value2': '1 Item inventory summary'}
]);

matches = match('/xxx/input/%31%20%2F%20物品%20存货%20总结', [paramRoute]);
expect(routes(matches), [paramRoute]);
expect(params(matches), [
{'value': 'input', 'value2': '1 / 物品 存货 总结'}
]);

matches = match(
'/xxx/input/%31%20%2F%20Item%20inventory%20summary', [paramRoute]);
expect(routes(matches), [paramRoute]);
Expand Down
Loading