mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Ensure IPv6 are bracketed if it's with query or path
This commit is contained in:
parent
74c18d8195
commit
9017ce6b9d
2 changed files with 22 additions and 1 deletions
|
|
@ -54,14 +54,17 @@ namespace Flow.Launcher.Test.Plugins
|
||||||
[TestCase("http://example.com/path")]
|
[TestCase("http://example.com/path")]
|
||||||
[TestCase("https://example.com/path?query=1")]
|
[TestCase("https://example.com/path?query=1")]
|
||||||
[TestCase("192.168.1.1/path/to/resource")]
|
[TestCase("192.168.1.1/path/to/resource")]
|
||||||
|
[TestCase("192.168.1.1/path/to/resource?query=1")]
|
||||||
[TestCase("localhost:8080/api/endpoint")]
|
[TestCase("localhost:8080/api/endpoint")]
|
||||||
[TestCase("http://localhost/path")]
|
[TestCase("http://localhost/path")]
|
||||||
[TestCase("[::1]/path")]
|
[TestCase("[::1]/path")]
|
||||||
|
[TestCase("[2001:db8::1]/path?query=1")]
|
||||||
public void WhenValidUrlThenIsUrlReturnsTrue(string url)
|
public void WhenValidUrlThenIsUrlReturnsTrue(string url)
|
||||||
{
|
{
|
||||||
Assert.That(plugin.IsURL(url), Is.True);
|
Assert.That(plugin.IsURL(url), Is.True);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestCase("2001:db8::1/path")]
|
||||||
[TestCase("wwww")]
|
[TestCase("wwww")]
|
||||||
[TestCase("wwww.c")]
|
[TestCase("wwww.c")]
|
||||||
[TestCase("not a url")]
|
[TestCase("not a url")]
|
||||||
|
|
|
||||||
|
|
@ -94,8 +94,25 @@ namespace Flow.Launcher.Plugin.Url
|
||||||
|
|
||||||
// Check if it's a bare IP address with optional port, path, query, or fragment
|
// Check if it's a bare IP address with optional port, path, query, or fragment
|
||||||
var ipPart = input.Split('/', '?', '#')[0]; // Remove path, query, and fragment
|
var ipPart = input.Split('/', '?', '#')[0]; // Remove path, query, and fragment
|
||||||
if (IPEndPoint.TryParse(ipPart, out var endpoint) && !endpoint.Address.Equals(IPAddress.Any) && !endpoint.Address.Equals(IPAddress.IPv6Any))
|
if (IPEndPoint.TryParse(ipPart, out var endpoint))
|
||||||
|
{
|
||||||
|
switch (endpoint.AddressFamily)
|
||||||
|
{
|
||||||
|
case System.Net.Sockets.AddressFamily.InterNetwork:
|
||||||
|
return !endpoint.Address.Equals(IPAddress.Any);
|
||||||
|
case System.Net.Sockets.AddressFamily.InterNetworkV6:
|
||||||
|
if (input.Contains('/') || input.Contains('?') || input.Contains('#'))
|
||||||
|
{
|
||||||
|
// Check if IPv6 address is properly bracketed
|
||||||
|
var bracketStart = input.IndexOf('[');
|
||||||
|
var bracketEnd = input.IndexOf(']');
|
||||||
|
if (bracketStart == -1 || bracketEnd == -1 || bracketStart > bracketEnd)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !endpoint.Address.Equals(IPAddress.IPv6Any);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Add protocol if missing for Uri validation
|
// Add protocol if missing for Uri validation
|
||||||
var urlToValidate = UrlSchemes.Any(s => input.StartsWith(s, StringComparison.OrdinalIgnoreCase))
|
var urlToValidate = UrlSchemes.Any(s => input.StartsWith(s, StringComparison.OrdinalIgnoreCase))
|
||||||
|
|
@ -105,6 +122,7 @@ namespace Flow.Launcher.Plugin.Url
|
||||||
if (!Uri.TryCreate(urlToValidate, UriKind.Absolute, out var uri))
|
if (!Uri.TryCreate(urlToValidate, UriKind.Absolute, out var uri))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
// Validate protocol
|
// Validate protocol
|
||||||
if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps && uri.Scheme != Uri.UriSchemeFtp)
|
if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps && uri.Scheme != Uri.UriSchemeFtp)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue