Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing PathBase. #1198

Merged
merged 17 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
37 changes: 24 additions & 13 deletions src/Sentry.AspNetCore/Extensions/HttpContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ internal static class HttpContextExtensions
return null;
}

var builder = new StringBuilder()
.AppendIf(context.Request.PathBase.HasValue, context.Request.PathBase.Value?.TrimStart('/'))
.AppendIf(context.Request.PathBase.HasValue, '/');
var builder = new StringBuilder();
if (context.Request.PathBase.HasValue)
{
builder.Append(context.Request.PathBase.Value?.TrimStart('/'))
.Append('/');
}

// Skip route pattern if it resembles to a MVC route or null e.g.
// {controller=Home}/{action=Index}/{id?}
return RouteHasMvcParameters(routePattern)
Expand All @@ -57,18 +61,25 @@ internal static class HttpContextExtensions
var action = routeData?.Values["action"]?.ToString();
var area = routeData?.Values["area"]?.ToString();

if (!string.IsNullOrWhiteSpace(action))
if (string.IsNullOrWhiteSpace(action) is false)
lucas-zimerman marked this conversation as resolved.
Show resolved Hide resolved
{
var hasArea = !string.IsNullOrWhiteSpace(area);
return new StringBuilder()
.AppendIf(context.Request.PathBase.HasValue, context.Request.PathBase.Value?.TrimStart('/'))
.AppendIf(context.Request.PathBase.HasValue, '.')
.AppendIf(hasArea, area)
.AppendIf(hasArea, '.')
.Append(controller)
var builder = new StringBuilder();
if (context.Request.PathBase.HasValue)
{
builder.Append(context.Request.PathBase.Value?.TrimStart('/'))
.Append('.');
}

if (string.IsNullOrWhiteSpace(area) is false)
lucas-zimerman marked this conversation as resolved.
Show resolved Hide resolved
{
builder.Append(area)
.Append('.');
}

builder.Append(controller)
.Append('.')
.Append(action)
.ToString();
.Append(action);
return builder.ToString();
}

// If the handler doesn't use routing (i.e. it checks `context.Request.Path` directly),
Expand Down
13 changes: 0 additions & 13 deletions src/Sentry.AspNetCore/Extensions/StringBuilderExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public HttpContext GetSut(string pathBase = null)
return httpContext;
}

public HttpContext GetMvcSut(string area = null, string controller = null, string action = null
public HttpContext GetMvcSut(
string area = null,
string controller = null,
string action = null
, string pathBase = null)
lucas-zimerman marked this conversation as resolved.
Show resolved Hide resolved
{
var httpContext = new DefaultHttpContext();
Expand Down