Skip to content

Commit 5bcdbbc

Browse files
franky920920jaimecbernardo
authored andcommitted
[PT Run] Add scheme verification for application URI (#15324)
* [PT Run] Add scheme verfication for application URI * Add test
1 parent b609403 commit 5bcdbbc

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/modules/launcher/Plugins/Microsoft.Plugin.Uri.UnitTests/UriHelper/ExtendedUriParserTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public class ExtendedUriParserTests
7878
[DataRow("ftp://user:[email protected]:2121", true, "ftp://user:[email protected]:2121/", false)]
7979
[DataRow("ftp://user:[email protected]", true, "ftp://user:[email protected]/", false)]
8080
[DataRow("ftp://user:[email protected]:2121", true, "ftp://user:[email protected]:2121/", false)]
81+
[DataRow("^:", false, null, false)]
8182

8283
public void TryParseCanParseHostName(string query, bool expectedSuccess, string expectedResult, bool expectedIsWebUri)
8384
{

src/modules/launcher/Plugins/Microsoft.Plugin.Uri/UriHelper/ExtendedUriParser.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Linq;
7+
using System.Text.RegularExpressions;
78
using Microsoft.Plugin.Uri.Interfaces;
89

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

2223
// Handling URL with only scheme, typically mailto or application uri.
2324
// Do nothing, return the result without urlBuilder
25+
// And check if scheme match REC3986 (issue #15035)
26+
const string schemeRegex = @"^([a-z][a-z0-9+\-.]*):";
2427
if (input.EndsWith(":", StringComparison.OrdinalIgnoreCase)
2528
&& !input.StartsWith("http", StringComparison.OrdinalIgnoreCase)
2629
&& !input.Contains("/", StringComparison.OrdinalIgnoreCase)
27-
&& !input.All(char.IsDigit))
30+
&& !input.All(char.IsDigit)
31+
&& Regex.IsMatch(input, schemeRegex))
2832
{
2933
result = new System.Uri(input);
3034
isWebUri = false;

0 commit comments

Comments
 (0)