From 0e3e7ee9bbd63ad80708d78f7ca6ccc90d710223 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sun, 3 Feb 2019 00:52:48 -0500 Subject: [PATCH] 3.0.3 --- CHANGELOG.md | 3 +++ example/main.dart | 5 ++--- lib/src/grammar.dart | 30 +++++++++++++++--------------- pubspec.yaml | 2 +- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be1c2116..33f71044 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 3.0.3 +* Support trailing text after parameters with custom Regexes. + # 3.0.2 * Support leading and trailing text for both `:parameters` and `*` diff --git a/example/main.dart b/example/main.dart index b3d6714a..19063678 100644 --- a/example/main.dart +++ b/example/main.dart @@ -9,12 +9,11 @@ main() { router.get('/wild*', () {}); - // TODO: Enable trailing after custom RegExp - // router.get('/ordinal/int:n([0-9]+)st', () {}); + router.get('/ordinal/int:n([0-9]+)st', () {}); print(router.resolveAbsolute('/whois/~thosakwe').first.allParams); print(router.resolveAbsolute('/wild_thornberrys').first.route.path); - // print(router.resolveAbsolute('/ordinal/1st').first.allParams); + print(router.resolveAbsolute('/ordinal/1st').first.allParams); router.get('/users', () {}); diff --git a/lib/src/grammar.dart b/lib/src/grammar.dart index 886fc2c8..152d73ce 100644 --- a/lib/src/grammar.dart +++ b/lib/src/grammar.dart @@ -7,13 +7,11 @@ class RouteGrammar { match(new RegExp(notSlashRgx)).value((r) => r.span.text); static final Parser regExp = - // TODO: Enable trailing here - // match(new RegExp(r'\(([^)]+)\)([^/]+)?')) - match(new RegExp(r'\(([^)]+)\)')) + match(new RegExp(r'\(([^\n)]+)\)([^/]+)?')) .value((r) => r.scanner.lastMatch); static final Parser parameterName = match( - new RegExp('$notSlashRgx?' r':([A-Za-z0-9_]+)' '$notSlashRgx?')) + new RegExp('$notSlashRgx?' r':([A-Za-z0-9_]+)' r'([^(/\n])?')) .value((r) => r.scanner.lastMatch); static final Parser parameterSegment = chain([ @@ -23,20 +21,22 @@ class RouteGrammar { ]).map((r) { var match = r.value[0] as Match; var rgxMatch = r.value[2] as Match; + + var pre = match[1] ?? ''; + var post = match[3] ?? ''; RegExp rgx; if (rgxMatch != null) { - rgx = RegExp(rgxMatch[1]); - var pre = match[1] ?? ''; - var post = rgxMatch[2] ?? ''; - post += match[3] ?? ''; - if (pre.isNotEmpty || post.isNotEmpty) { - if (rgx != null) { - var pattern = pre + rgx.pattern + post; - rgx = RegExp(pattern); - } else { - rgx = RegExp('$pre$notSlashRgx$post'); - } + rgx = RegExp('(${rgxMatch[1]})'); + post = (rgxMatch[2] ?? '') + post; + } + + if (pre.isNotEmpty || post.isNotEmpty) { + if (rgx != null) { + var pattern = pre + rgx.pattern + post; + rgx = RegExp(pattern); + } else { + rgx = RegExp('$pre$notSlashRgx$post'); } } diff --git a/pubspec.yaml b/pubspec.yaml index 1f4a0f1c..bf995998 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: angel_route description: A powerful, isomorphic routing library for Dart. It is mainly used in the Angel framework, but can be used in Flutter and on the Web. -version: 3.0.2 +version: 3.0.3 author: Tobe O homepage: https://github.com/angel-dart/angel_route environment: