mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
fix #216. Cound't open url with port
This commit is contained in:
parent
82106c1c8b
commit
443e7df1b6
3 changed files with 94 additions and 3 deletions
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Security.Policy;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
|
|
@ -10,13 +11,45 @@ namespace Wox.Plugin.SystemPlugins
|
|||
{
|
||||
public class UrlPlugin : BaseSystemPlugin
|
||||
{
|
||||
const string pattern = @"^(http|https|)\://|[a-zA-Z0-9\-\.]+\.[a-zA-Z](:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$";
|
||||
Regex reg = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
//based on https://gist.github.com/dperini/729294
|
||||
private const string urlPattern ="^" +
|
||||
// protocol identifier
|
||||
"(?:(?:https?|ftp)://|)" +
|
||||
// user:pass authentication
|
||||
"(?:\\S+(?::\\S*)?@)?" +
|
||||
"(?:" +
|
||||
// IP address exclusion
|
||||
// private & local networks
|
||||
"(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
|
||||
"(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
|
||||
"(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
|
||||
// IP address dotted notation octets
|
||||
// excludes loopback network 0.0.0.0
|
||||
// excludes reserved space >= 224.0.0.0
|
||||
// excludes network & broacast addresses
|
||||
// (first & last IP address of each class)
|
||||
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
|
||||
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
|
||||
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
|
||||
"|" +
|
||||
// host name
|
||||
"(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
|
||||
// domain name
|
||||
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
|
||||
// TLD identifier
|
||||
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
|
||||
")" +
|
||||
// port number
|
||||
"(?::\\d{2,5})?" +
|
||||
// resource path
|
||||
"(?:/\\S*)?" +
|
||||
"$";
|
||||
Regex reg = new Regex(urlPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
protected override List<Result> QueryInternal(Query query)
|
||||
{
|
||||
var raw = query.RawQuery;
|
||||
if (reg.Match(raw).Value == raw)
|
||||
if (IsURL(raw))
|
||||
{
|
||||
return new List<Result>
|
||||
{
|
||||
|
|
@ -49,6 +82,23 @@ namespace Wox.Plugin.SystemPlugins
|
|||
return new List<Result>(0);
|
||||
}
|
||||
|
||||
public bool IsURL(string raw)
|
||||
{
|
||||
raw = raw.ToLower();
|
||||
|
||||
if (reg.Match(raw).Value == raw) return true;
|
||||
|
||||
if (raw == "localhost" || raw.StartsWith("localhost:") ||
|
||||
raw == "http://localhost" || raw.StartsWith("http://localhost:") ||
|
||||
raw == "https://localhost" || raw.StartsWith("https://localhost:")
|
||||
)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ID
|
||||
{
|
||||
get { return "0308FD86DE0A4DEE8D62B9B535370992"; }
|
||||
|
|
|
|||
36
Wox.Test/UrlPluginTest.cs
Normal file
36
Wox.Test/UrlPluginTest.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using NUnit.Framework;
|
||||
using Wox.Plugin.SystemPlugins;
|
||||
|
||||
namespace Wox.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class UrlPluginTest
|
||||
{
|
||||
[Test]
|
||||
public void URLMatchTest()
|
||||
{
|
||||
UrlPlugin urlPlugin = new UrlPlugin();
|
||||
Assert.IsTrue(urlPlugin.IsURL("http://www.google.com"));
|
||||
Assert.IsTrue(urlPlugin.IsURL("https://www.google.com"));
|
||||
Assert.IsTrue(urlPlugin.IsURL("http://google.com"));
|
||||
Assert.IsTrue(urlPlugin.IsURL("www.google.com"));
|
||||
Assert.IsTrue(urlPlugin.IsURL("google.com"));
|
||||
Assert.IsTrue(urlPlugin.IsURL("http://localhost"));
|
||||
Assert.IsTrue(urlPlugin.IsURL("https://localhost"));
|
||||
Assert.IsTrue(urlPlugin.IsURL("http://localhost:80"));
|
||||
Assert.IsTrue(urlPlugin.IsURL("https://localhost:80"));
|
||||
Assert.IsTrue(urlPlugin.IsURL("http://110.10.10.10"));
|
||||
Assert.IsTrue(urlPlugin.IsURL("110.10.10.10"));
|
||||
Assert.IsTrue(urlPlugin.IsURL("ftp://110.10.10.10"));
|
||||
|
||||
|
||||
Assert.IsFalse(urlPlugin.IsURL("wwww"));
|
||||
Assert.IsFalse(urlPlugin.IsURL("wwww.c"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -46,6 +46,7 @@
|
|||
<Compile Include="FuzzyMatcherTest.cs" />
|
||||
<Compile Include="QueryTest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="UrlPluginTest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
|
@ -55,6 +56,10 @@
|
|||
<Project>{4FD29318-A8AB-4D8F-AA47-60BC241B8DA3}</Project>
|
||||
<Name>Wox.Infrastructure</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Wox.Plugin.SystemPlugins\Wox.Plugin.SystemPlugins.csproj">
|
||||
<Project>{69CE0206-CB41-453D-88AF-DF86092EF9B8}</Project>
|
||||
<Name>Wox.Plugin.SystemPlugins</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Wox.Plugin\Wox.Plugin.csproj">
|
||||
<Project>{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}</Project>
|
||||
<Name>Wox.Plugin</Name>
|
||||
|
|
|
|||
Loading…
Reference in a new issue