From 2b5a4ba6cab40ec27425b1538a23b6b896640470 Mon Sep 17 00:00:00 2001 From: iyifr Date: Sat, 24 Aug 2024 02:45:45 +0100 Subject: [PATCH] fix:regex pattern matches all route patterns --- bin/main.dart | 4 ---- lib/src/extract_path_pieces.dart | 4 +++- lib/src/logger.dart | 23 ++++++++++++++++++++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index ff657d7..112442d 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -22,8 +22,4 @@ void main() async { router.get("/hi", (event) { throw CreateError(message: "HAHA"); }); - - router.get('#', (event) { - return 'Hi'; - }); } diff --git a/lib/src/extract_path_pieces.dart b/lib/src/extract_path_pieces.dart index 3ad49a3..5813353 100644 --- a/lib/src/extract_path_pieces.dart +++ b/lib/src/extract_path_pieces.dart @@ -14,10 +14,12 @@ bool isValidHttpPathPattern(String pattern) { r'/' r'|/(?:[\p{L}\p{N}_-]+(?:/[\p{L}\p{N}_-]+)*/?)' r'|/(?:[\p{L}\p{N}_-]+(?:/[\p{L}\p{N}_-]+)*/)*:(?:[\p{L}\p{N}_]+)(?:/|$)' + r'|/[\p{L}\p{N}_-]+/:[^/]+/\*\*' + r'|/[\p{L}\p{N}_-]+/\*\*' + r'|/[\p{L}\p{N}_-]+/\*' r'|\*' r')$', unicode: true, ); - return regex.hasMatch(pattern); } diff --git a/lib/src/logger.dart b/lib/src/logger.dart index ff8b61b..1bfdad9 100644 --- a/lib/src/logger.dart +++ b/lib/src/logger.dart @@ -1,10 +1,31 @@ import 'package:logging/logging.dart'; +import 'package:console/console.dart'; var logger = Logger('H4'); initLogger() { Logger.root.level = Level.ALL; // defaults to Level.INFO Logger.root.onRecord.listen((record) { - print('${record.level.name}: ${record.message}'); + switch (record.level.name) { + case 'INFO': + { + Console.setBackgroundColor(6, bright: true); + Console.setTextColor(2, bright: true); + // ignore: unnecessary_string_escapes + Console.write('\n ${record.level.name} '); + Console.resetBackgroundColor(); + Console.resetTextColor(); + Console.setBold(false); + Console.write(' ▲▼▲▼▲▼ ${record.message}\n'); + Console.resetAll(); + } + + case 'SEVERE': + { + Console.setFramed(true); + Console.write(record.level.name); + Console.write(record.message); + } + } }); }