Skip to content

Commit b2427e8

Browse files
committed
Merge branch 'pr101' into develop
* pr101: (GH-70) Added validation if URL is SSL capable.
2 parents 37d92b6 + 60a38fe commit b2427e8

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/Chocolatey.Language.Server/UriExtensions.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Net;
33

4-
namespace Chocolatey.Language.Server.Utility
4+
namespace Chocolatey.Language.Server
55
{
66
/// <summary>
77
/// Extensions for Uri
@@ -32,5 +32,25 @@ public static bool IsValid(this Uri url)
3232
return false;
3333
}
3434
}
35+
36+
/// <summary>
37+
/// Tries to validate if an URL is SSL capable.
38+
/// HTTP: Will return true if the URL validates with SSL, otherwise false.
39+
/// HTTPS: it returns false
40+
/// </summary>
41+
/// <param name="url">Uri object</param>
42+
public static bool SslCapable(this Uri url)
43+
{
44+
if (url.Scheme.Equals(Uri.UriSchemeHttps))
45+
{
46+
return false;
47+
}
48+
49+
var uri = new UriBuilder(url);
50+
// Handle http: override the scheme and use the default https port
51+
uri.Scheme = Uri.UriSchemeHttps;
52+
uri.Port = -1;
53+
return uri.Uri.IsValid();
54+
}
3555
}
3656
}

src/Chocolatey.Language.Server/Validations/UrlValidValidation.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using Chocolatey.Language.Server.Utility;
4+
using Chocolatey.Language.Server;
55
using Microsoft.Language.Xml;
66
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
77
using DiagnosticSeverity = OmniSharp.Extensions.LanguageServer.Protocol.Models.DiagnosticSeverity;
@@ -34,7 +34,7 @@ public IEnumerable<Diagnostic> Validate(XmlDocumentSyntax syntaxTree, TextPositi
3434
if (element != null) {
3535
var uriString = element.GetContentValue().Trim();
3636
Uri uri;
37-
if(
37+
if (
3838
!Uri.IsWellFormedUriString(uriString, UriKind.Absolute) ||
3939
!Uri.TryCreate(uriString, UriKind.Absolute, out uri) ||
4040
!uri.IsValid()
@@ -47,6 +47,19 @@ public IEnumerable<Diagnostic> Validate(XmlDocumentSyntax syntaxTree, TextPositi
4747
Range = range
4848
};
4949
}
50+
else
51+
{
52+
if (uri.SslCapable())
53+
{
54+
var range = textPositions.GetRange(element.StartTag.End, element.EndTag.Start);
55+
56+
yield return new Diagnostic {
57+
Message = "Url in " + elementName + " is SSL capable, please switch to https.",
58+
Severity = DiagnosticSeverity.Warning,
59+
Range = range
60+
};
61+
}
62+
}
5063
}
5164
}
5265
}

0 commit comments

Comments
 (0)