diff --git a/src/Umbraco.Core/Extensions/StringExtensions.cs b/src/Umbraco.Core/Extensions/StringExtensions.cs
index 8902712a19..70c959d09f 100644
--- a/src/Umbraco.Core/Extensions/StringExtensions.cs
+++ b/src/Umbraco.Core/Extensions/StringExtensions.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Umbraco.
+// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
@@ -1259,51 +1259,6 @@ namespace Umbraco.Extensions
&& Path.GetPathRoot(path).Equals(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) == false;
}
- ///
- /// Based on the input string, this will detect if the string is a JS path or a JS snippet.
- /// If a path cannot be determined, then it is assumed to be a snippet the original text is returned
- /// with an invalid attempt, otherwise a valid attempt is returned with the resolved path
- ///
- ///
- ///
- ///
- /// This is only used for legacy purposes for the Action.JsSource stuff and shouldn't be needed in v8
- ///
- internal static Attempt DetectIsJavaScriptPath(this string input, IIOHelper ioHelper)
- {
- //validate that this is a url, if it is not, we'll assume that it is a text block and render it as a text
- //block instead.
- var isValid = true;
-
- if (Uri.IsWellFormedUriString(input, UriKind.RelativeOrAbsolute))
- {
- //ok it validates, but so does alert('hello'); ! so we need to do more checks
-
- //here are the valid chars in a url without escaping
- if (Regex.IsMatch(input, @"[^a-zA-Z0-9-._~:/?#\[\]@!$&'\(\)*\+,%;=]"))
- isValid = false;
-
- //we'll have to be smarter and just check for certain js patterns now too!
- var jsPatterns = new[] { @"\+\s*\=", @"\);", @"function\s*\(", @"!=", @"==" };
- if (jsPatterns.Any(p => Regex.IsMatch(input, p)))
- isValid = false;
-
- if (isValid)
- {
- var resolvedUrlResult = ioHelper.TryResolveUrl(input);
- //if the resolution was success, return it, otherwise just return the path, we've detected
- // it's a path but maybe it's relative and resolution has failed, etc... in which case we're just
- // returning what was given to us.
- return resolvedUrlResult.Success
- ? resolvedUrlResult
- : Attempt.Succeed(input);
- }
- }
-
- return Attempt.Fail(input);
- }
-
-
// FORMAT STRINGS
///
diff --git a/src/Umbraco.Core/IO/IIOHelper.cs b/src/Umbraco.Core/IO/IIOHelper.cs
index a9057803f4..5a814ab386 100644
--- a/src/Umbraco.Core/IO/IIOHelper.cs
+++ b/src/Umbraco.Core/IO/IIOHelper.cs
@@ -8,11 +8,9 @@ namespace Umbraco.Cms.Core.IO
{
string FindFile(string virtualPath);
- // TODO: This is the same as IHostingEnvironment.ToAbsolute
+ [Obsolete("Use IHostingEnvironment.ToAbsolute instead")]
string ResolveUrl(string virtualPath);
- Attempt TryResolveUrl(string virtualPath);
-
///
/// Maps a virtual path to a physical path in the content root folder (i.e. www)
///
@@ -21,14 +19,6 @@ namespace Umbraco.Cms.Core.IO
[Obsolete("Use IHostingEnvironment.MapPathContentRoot or IHostingEnvironment.MapPathWebRoot instead")]
string MapPath(string path);
- ///
- /// Returns true if the path has a root, and is considered fully qualified for the OS it is on
- /// See https://github.com/dotnet/runtime/blob/30769e8f31b20be10ca26e27ec279cd4e79412b9/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs#L281 for the .NET Standard 2.1 version of this
- ///
- /// The path to check
- /// True if the path is fully qualified, false otherwise
- bool IsPathFullyQualified(string path);
-
///
/// Verifies that the current filepath matches a directory where the user is allowed to edit a file.
///
diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs
index 56db480632..e799bbdbe8 100644
--- a/src/Umbraco.Core/IO/IOHelper.cs
+++ b/src/Umbraco.Core/IO/IOHelper.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
@@ -36,7 +36,7 @@ namespace Umbraco.Cms.Core.IO
return retval;
}
- // TODO: This is the same as IHostingEnvironment.ToAbsolute
+ // TODO: This is the same as IHostingEnvironment.ToAbsolute - marked as obsolete in IIOHelper for now
public string ResolveUrl(string virtualPath)
{
if (string.IsNullOrWhiteSpace(virtualPath)) return virtualPath;
@@ -44,23 +44,6 @@ namespace Umbraco.Cms.Core.IO
}
- public Attempt TryResolveUrl(string virtualPath)
- {
- try
- {
- if (virtualPath.StartsWith("~"))
- return Attempt.Succeed(virtualPath.Replace("~", _hostingEnvironment.ApplicationVirtualPath).Replace("//", "/"));
- if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute))
- return Attempt.Succeed(virtualPath);
-
- return Attempt.Succeed(_hostingEnvironment.ToAbsolute(virtualPath));
- }
- catch (Exception ex)
- {
- return Attempt.Fail(virtualPath, ex);
- }
- }
-
public string MapPath(string path)
{
if (path == null) throw new ArgumentNullException(nameof(path));
diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/ShortStringHelper/StringExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/ShortStringHelper/StringExtensionsTests.cs
index c6a5510986..74d80d8665 100644
--- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/ShortStringHelper/StringExtensionsTests.cs
+++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/ShortStringHelper/StringExtensionsTests.cs
@@ -37,19 +37,6 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.ShortStringHelper
Assert.AreEqual(result, first.ToGuid() == second.ToGuid());
}
- [TestCase("alert('hello');", false)]
- [TestCase("~/Test.js", true)]
- [TestCase("../Test.js", true)]
- [TestCase("/Test.js", true)]
- [TestCase("Test.js", true)]
- [TestCase("Test.js==", false)]
- [TestCase("/Test.js function(){return true;}", false)]
- public void Detect_Is_JavaScript_Path(string input, bool result)
- {
- Attempt output = input.DetectIsJavaScriptPath(Mock.Of());
- Assert.AreEqual(result, output.Success);
- }
-
[TestCase("hello.txt", "hello")]
[TestCase("this.is.a.Txt", "this.is.a")]
[TestCase("this.is.not.a. Txt", "this.is.not.a. Txt")]