Skip to content

Commit 6120e5e

Browse files
RegEx timeout warning (#17716)
* RegEx timeout warning * RegEx timeout warning * Update aspnetcore/mvc/controllers/routing.md Co-Authored-By: Kirk Larkin <6025110+serpent5@users.noreply.github.com> Co-authored-by: Kirk Larkin <6025110+serpent5@users.noreply.github.com>
1 parent dd14ea8 commit 6120e5e

4 files changed

Lines changed: 11 additions & 12 deletions

File tree

aspnetcore/fundamentals/routing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ Using a template is generally the simplest approach to routing. Constraints and
449449
Complex segments are processed by matching up literal delimiters from right to left in a [non-greedy](#greedy) way. For example, `[Route("/a{b}c{d}")]` is a complex segment.
450450
Complex segments work in a particular way that must be understood to use them successfully. The example in this section demonstrates why complex segments only really work well when the delimiter text doesn't appear inside the parameter values. Using a [regex](/dotnet/standard/base-types/regular-expressions) and then manually extracting the values is needed for more complex cases.
451451

452+
[!INCLUDE[](~/includes/regex.md)]
453+
452454
This is a summary of the steps that routing performs with the template `/a{b}c{d}` and the URL path `/abcd`. The `|` is used to help visualize how the algorithm works:
453455

454456
* The first literal, right to left, is `c`. So `/abcd` is searched from right and finds `/ab|c|d`.

aspnetcore/mvc/controllers/routing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ The `RouteTokenTransformerConvention` is registered as an option in `ConfigureSe
524524

525525
See [MDN web docs on Slug](https://developer.mozilla.org/docs/Glossary/Slug) for the definition of Slug.
526526

527+
[!INCLUDE[](~/includes/regex.md)]
527528
<a name="routing-multiple-routes-ref-label"></a>
528529

529530
### Multiple attribute routes

aspnetcore/mvc/controllers/routing/samples/3.x/main/StartupSlugifyParamTransformer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.Extensions.Configuration;
66
using Microsoft.Extensions.DependencyInjection;
77
using Microsoft.Extensions.Hosting;
8+
using System;
89
using System.Text.RegularExpressions;
910

1011
namespace WebMvcRouting
@@ -63,9 +64,11 @@ public string TransformOutbound(object value)
6364
{
6465
if (value == null) { return null; }
6566

66-
// Slugify value
6767
return Regex.Replace(value.ToString(),
68-
"([a-z])([A-Z])", "$1-$2").ToLowerInvariant();
68+
"([a-z])([A-Z])",
69+
"$1-$2",
70+
RegexOptions.CultureInvariant,
71+
TimeSpan.FromMilliseconds(100)).ToLowerInvariant();
6972
}
7073
}
7174
#endregion

aspnetcore/razor-pages/razor-pages-conventions.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,11 @@ public void ConfigureServices(IServiceCollection services)
186186
new SlugifyParameterTransformer()));
187187
});
188188
}
189+
```
189190

190-
public class SlugifyParameterTransformer : IOutboundParameterTransformer
191-
{
192-
public string TransformOutbound(object value)
193-
{
194-
if (value == null) { return null; }
191+
[!code-csharp[](~/mvc/controllers/routing/samples/3.x/main/StartupSlugifyParamTransformer.cs?name=snippet2)]
195192

196-
// Slugify value
197-
return Regex.Replace(value.ToString(), "([a-z])([A-Z])", "$1-$2").ToLower();
198-
}
199-
}
200-
```
193+
[!INCLUDE[](~/includes/regex.md)]
201194

202195
## Configure a page route
203196

0 commit comments

Comments
 (0)