[PT Run] Add scheme verification for application URI (#15324)

* [PT Run] Add scheme verfication for application URI

* Add test
This commit is contained in:
Franky Chen
2022-01-11 12:13:41 +00:00
committed by GitHub
parent bcba63e4b2
commit d52037fd5e
2 changed files with 6 additions and 1 deletions

View File

@@ -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@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("^:", false, null, false)]
public void TryParseCanParseHostName(string query, bool expectedSuccess, string expectedResult, bool expectedIsWebUri)
{

View File

@@ -4,6 +4,7 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Plugin.Uri.Interfaces;
namespace Microsoft.Plugin.Uri.UriHelper
@@ -21,10 +22,13 @@ namespace Microsoft.Plugin.Uri.UriHelper
// Handling URL with only scheme, typically mailto or application uri.
// 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)
&& !input.StartsWith("http", StringComparison.OrdinalIgnoreCase)
&& !input.Contains("/", StringComparison.OrdinalIgnoreCase)
&& !input.All(char.IsDigit))
&& !input.All(char.IsDigit)
&& Regex.IsMatch(input, schemeRegex))
{
result = new System.Uri(input);
isWebUri = false;