From a4e0c57e95ca4617907a996256fabe5f4c4d6148 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Thu, 31 Oct 2024 21:35:58 +0800 Subject: [PATCH] Update regex --- src/Aspire.Dashboard/ConsoleLogs/UrlParser.cs | 14 +++----------- .../ConsoleLogsTests/UrlParserTests.cs | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Aspire.Dashboard/ConsoleLogs/UrlParser.cs b/src/Aspire.Dashboard/ConsoleLogs/UrlParser.cs index 0b19a200ba..02e1d9fd3e 100644 --- a/src/Aspire.Dashboard/ConsoleLogs/UrlParser.cs +++ b/src/Aspire.Dashboard/ConsoleLogs/UrlParser.cs @@ -65,17 +65,9 @@ static void AppendNonMatchFragment(StringBuilder stringBuilder, Funchttp://bing.com/")] [InlineData("http://bing.com/dir", "http://bing.com/dir")] [InlineData("http://bing.com/index.aspx", "http://bing.com/index.aspx")] - [InlineData("http://bing", "http://bing")] + [InlineData("http://localhost", "http://localhost")] public void TryParse_SupportedUrlFormats(string input, string? expectedOutput) { var result = UrlParser.TryParse(input, WebUtility.HtmlEncode, out var modifiedText); @@ -83,4 +83,17 @@ public void GenerateUrlRegEx_MatchUrlAfterContent(string content) var match = regex.Match(content); Assert.Equal("http://www.localhost:8080", match.Value.ToLowerInvariant()); } + + [Theory] + [InlineData("http://www.localhost:8080!", "http://www.localhost:8080!")] + [InlineData("http://www.localhost:8080/path!", "http://www.localhost:8080/path!")] + [InlineData("http://www.localhost:8080/path;", "http://www.localhost:8080/path")] + [InlineData("http://www.localhost:8080;", "http://www.localhost:8080")] + [InlineData("http://www.local;host:8080;", "http://www.local")] + public void GenerateUrlRegEx_MatchUrlBeforeContent(string content, string expected) + { + var regex = UrlParser.GenerateUrlRegEx(); + var match = regex.Match(content); + Assert.Equal(expected, match.Value.ToLowerInvariant()); + } }