Skip to content

Commit

Permalink
[PT Run] Add scheme verification for application URI (#15324)
Browse files Browse the repository at this point in the history
* [PT Run] Add scheme verfication for application URI

* Add test
  • Loading branch information
franky920920 authored and jaimecbernardo committed Jan 11, 2022
1 parent b609403 commit 5bcdbbc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class ExtendedUriParserTests
[DataRow("ftp://user:[email protected]:2121", true, "ftp://user:[email protected]:2121/", false)]
[DataRow("ftp://user:[email protected]", true, "ftp://user:[email protected]/", false)]
[DataRow("ftp://user:[email protected]:2121", true, "ftp://user:[email protected]:2121/", false)]
[DataRow("^:", false, null, false)]

public void TryParseCanParseHostName(string query, bool expectedSuccess, string expectedResult, bool expectedIsWebUri)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Plugin.Uri.Interfaces;

namespace Microsoft.Plugin.Uri.UriHelper
Expand All @@ -21,10 +22,13 @@ public bool TryParse(string input, out System.Uri result, out bool isWebUri)

// 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;
Expand Down

0 comments on commit 5bcdbbc

Please sign in to comment.