Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/Swashbuckle.AspNetCore.SwaggerUI/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ window.onload = function () {
// Workaround for https://github.com/swagger-api/swagger-ui/issues/5945
configObject.urls.forEach(function (item) {
if (item.url.startsWith("http") || item.url.startsWith("/")) return;
item.url = window.location.href.replace("index.html", item.url).split('#')[0];
item.url = window.location.href.split(/[?#]/)[0].replace("index.html", item.url).split('#')[0];
});

// If validatorUrl is not explicitly provided, disable the feature by setting to null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ static void AssertResource(HttpResponseMessage response)
}
}

[Fact]
public async Task SwaggerUIMiddleware_InitializerScript_DropsQueryStringFromRelativeDocumentUrls()
{
var cancellationToken = TestContext.Current.CancellationToken;

var site = new TestSite(typeof(Basic.Startup), outputHelper);
using var client = site.BuildClient();

using var response = await client.GetAsync("/index.js", cancellationToken);

Assert.Equal(HttpStatusCode.OK, response.StatusCode);

var jsContent = await response.Content.ReadAsStringAsync(cancellationToken);

Assert.Contains("window.location.href.split(/[?#]/)[0].replace(\"index.html\", item.url)", jsContent);
}
Comment thread
martincostello marked this conversation as resolved.
Resolved

[Theory]
[InlineData(typeof(Basic.Startup), "/index.js")]
[InlineData(typeof(CustomUIConfig.Startup), "/swagger/index.js")]
Expand Down