mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
[PT Run] Add scheme verification for application URI (#15324)
* [PT Run] Add scheme verfication for application URI * Add test
This commit is contained in:
@@ -78,6 +78,7 @@ namespace Microsoft.Plugin.Uri.UnitTests.UriHelper
|
|||||||
[DataRow("ftp://user:password@google.com:2121", true, "ftp://user:password@google.com:2121/", false)]
|
[DataRow("ftp://user:password@google.com:2121", true, "ftp://user:password@google.com:2121/", false)]
|
||||||
[DataRow("ftp://user:password@1.1.1.1", true, "ftp://user:password@1.1.1.1/", false)]
|
[DataRow("ftp://user:password@1.1.1.1", true, "ftp://user:password@1.1.1.1/", false)]
|
||||||
[DataRow("ftp://user:password@1.1.1.1:2121", true, "ftp://user:password@1.1.1.1:2121/", false)]
|
[DataRow("ftp://user:password@1.1.1.1:2121", true, "ftp://user:password@1.1.1.1:2121/", false)]
|
||||||
|
[DataRow("^:", false, null, false)]
|
||||||
|
|
||||||
public void TryParseCanParseHostName(string query, bool expectedSuccess, string expectedResult, bool expectedIsWebUri)
|
public void TryParseCanParseHostName(string query, bool expectedSuccess, string expectedResult, bool expectedIsWebUri)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using Microsoft.Plugin.Uri.Interfaces;
|
using Microsoft.Plugin.Uri.Interfaces;
|
||||||
|
|
||||||
namespace Microsoft.Plugin.Uri.UriHelper
|
namespace Microsoft.Plugin.Uri.UriHelper
|
||||||
@@ -21,10 +22,13 @@ namespace Microsoft.Plugin.Uri.UriHelper
|
|||||||
|
|
||||||
// Handling URL with only scheme, typically mailto or application uri.
|
// Handling URL with only scheme, typically mailto or application uri.
|
||||||
// Do nothing, return the result without urlBuilder
|
// Do nothing, return the result without urlBuilder
|
||||||
|
// And check if scheme match REC3986 (issue #15035)
|
||||||
|
const string schemeRegex = @"^([a-z][a-z0-9+\-.]*):";
|
||||||
if (input.EndsWith(":", StringComparison.OrdinalIgnoreCase)
|
if (input.EndsWith(":", StringComparison.OrdinalIgnoreCase)
|
||||||
&& !input.StartsWith("http", StringComparison.OrdinalIgnoreCase)
|
&& !input.StartsWith("http", StringComparison.OrdinalIgnoreCase)
|
||||||
&& !input.Contains("/", StringComparison.OrdinalIgnoreCase)
|
&& !input.Contains("/", StringComparison.OrdinalIgnoreCase)
|
||||||
&& !input.All(char.IsDigit))
|
&& !input.All(char.IsDigit)
|
||||||
|
&& Regex.IsMatch(input, schemeRegex))
|
||||||
{
|
{
|
||||||
result = new System.Uri(input);
|
result = new System.Uri(input);
|
||||||
isWebUri = false;
|
isWebUri = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user