Skip to content

Commit 0a06110

Browse files
committed
test: add test for serving files with whitespaces in their name
This test verifies that TryGetResponseContent can handle file paths containing whitespaces and serves the expected content, ensuring the URL-encoding fix works as intended.
1 parent dfe30bc commit 0a06110

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/Components/WebView/WebView/test/StaticContentProviderTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,38 @@ public void TryGetResponseContentReturnsCorrectContentTypeForNonPhysicalFile()
4141
Assert.Equal("text/css", contentTypeValue);
4242
}
4343

44+
[Fact]
45+
public void TryGetResponseContentCanHandleWhitespaceInFileName()
46+
{
47+
// Arrange
48+
const string cssFilePath = "file with whitespace.css";
49+
const string cssFileContent = "this is css";
50+
var inMemoryFileProvider = new InMemoryFileProvider(
51+
new Dictionary<string, string>
52+
{
53+
{ cssFilePath, cssFileContent },
54+
});
55+
var appBase = "fake://0.0.0.0/";
56+
var scp = new StaticContentProvider(inMemoryFileProvider, new Uri(appBase), "fakehost.html");
57+
58+
// Act
59+
Assert.True(scp.TryGetResponseContent(
60+
requestUri: appBase + Uri.EscapeDataString(cssFilePath),
61+
allowFallbackOnHostPage: false,
62+
out var statusCode,
63+
out var statusMessage,
64+
out var content,
65+
out var headers));
66+
67+
// Assert
68+
var contentString = new StreamReader(content).ReadToEnd();
69+
Assert.Equal(200, statusCode);
70+
Assert.Equal("OK", statusMessage);
71+
Assert.Equal("this is css", contentString);
72+
Assert.True(headers.TryGetValue("Content-Type", out var contentTypeValue));
73+
Assert.Equal("text/css", contentTypeValue);
74+
}
75+
4476
private sealed class InMemoryFileProvider : IFileProvider
4577
{
4678
public InMemoryFileProvider(IDictionary<string, string> filePathsAndContents)

0 commit comments

Comments
 (0)