Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Migrated UrlContext, HtmlEncode/Decode and UrlEncode/Decode to FubuMV…

…C.Core
  • Loading branch information...
commit c21e5bd109ae64372791a483cf0a96fa0de7ee98 1 parent c48698f
@spascoe spascoe authored
View
1  src/FubuCore.Testing/FubuCore.Testing.csproj
@@ -176,7 +176,6 @@
<Compile Include="TimeSpanExtensionsTester.cs" />
<Compile Include="TypeExtensionsTester.cs" />
<Compile Include="TypeResolverTester.cs" />
- <Compile Include="UrlContextTester.cs" />
<Compile Include="Util\CacheTester.cs" />
<Compile Include="Util\CompositePredicateTester.cs" />
<Compile Include="Util\DictionaryKeyValuesTester.cs" />
View
90 src/FubuCore.Testing/UrlContextTester.cs
@@ -1,90 +0,0 @@
-using System;
-using FubuTestingSupport;
-using NUnit.Framework;
-
-namespace FubuCore.Testing
-{
- [TestFixture]
- public class UrlContextTester
- {
- private const string SERVER_BASE = "http://www.someserver/ignored/path";
- /**************************************************************************
- * These tests really only confirm the Stubbed behavior, which is only
- * useful in the context of other tests.
- *
- * The real (live) behavior is tested via qunit in the FubuMVC.HelloWorld project.
- * To run the test, start the FubuMVC.HelloWorld project and navigate to:
- * http://localhost:52010/helloworld/IntegrationTests/run
- *
- * The source of the tests is in:
- * FubuMVC.HelloWorld\Controllers\IntegrationTests\RunView.aspx
- **************************************************************************/
-
- //[Test]
- //public void get_absolute_for_unrooted_url_with_empty_stubbed_root()
- //{
- // UrlContext.Stub("");
- // "someUrl".ToAbsoluteUrl().ShouldEqual("someUrl");
- //}
-
- //[SetUp]
- //public void SetUp()
- //{
- // UrlContext.Stub("/app");
- //}
-
- [Test]
- public void get_absolute_for_unrooted_url()
- {
- "someUrl".ToAbsoluteUrl("http://server").ShouldEqual("http://server/someUrl");
- }
-
- [Test]
- public void get_absolute_for_rooted_url()
- {
- "/folder/someUrl".ToAbsoluteUrl("http://server").ShouldEqual("http://server/folder/someUrl");
- }
-
- [Test]
- public void get_absolute_for_rooted_url_with_route_info()
- {
- "/folder/someUrl/{something}".ToAbsoluteUrl("http://server").ShouldEqual("http://server/folder/someUrl/{something}");
- }
-
- [Test]
- public void get_absolute_for_app_relative_url()
- {
- "~/someUrl".ToAbsoluteUrl("http://server/app").ShouldEqual("http://server/app/someUrl");
- }
-
- [Test]
- public void get_absolute_for_fully_qualified_url()
- {
- "http://somewhere.com/someUrl".ToAbsoluteUrl("http://server").ShouldEqual("http://somewhere.com/someUrl");
- }
-
- [Test]
- public void get_absolute_for_empty_url()
- {
- "".ToAbsoluteUrl("http://server").ShouldEqual("http://server");
- }
-
- [Test]
- public void get_server_url_for_fully_qualified_url()
- {
- "http://somewhere.com/someUrl".ToServerQualifiedUrl(SERVER_BASE).ShouldEqual("http://somewhere.com/someUrl");
- }
-
- [Test]
- public void get_url_without_querystring()
- {
- "/someUrl?query=foo".WithoutQueryString().ShouldEqual(@"/someUrl");
- }
-
- [Test]
- public void get_url_without_querystring_having_no_querystring_does_nothing()
- {
- "/someUrl".WithoutQueryString().ShouldEqual(@"/someUrl");
- }
- }
-}
View
2  src/FubuCore/FubuCore.csproj
@@ -37,7 +37,6 @@
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
- <Reference Include="System.Web" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
@@ -256,7 +255,6 @@
<Compile Include="TemplateParser.cs" />
<Compile Include="TypeExtensions.cs" />
<Compile Include="TypeResolver.cs" />
- <Compile Include="UrlContext.cs" />
<Compile Include="Util\BuildersAndAlterations.cs" />
<Compile Include="Util\Cache.cs" />
<Compile Include="Util\CompositeAction.cs" />
View
26 src/FubuCore/StringExtensions.cs
@@ -6,7 +6,6 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
-using System.Web;
using System.Linq;
namespace FubuCore
@@ -138,31 +137,6 @@ public static string Capitalize(this string stringValue)
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(stringValue);
}
- public static string HtmlAttributeEncode(this string unEncoded)
- {
- return HttpUtility.HtmlAttributeEncode(unEncoded);
- }
-
- public static string HtmlEncode(this string unEncoded)
- {
- return HttpUtility.HtmlEncode(unEncoded);
- }
-
- public static string HtmlDecode(this string encoded)
- {
- return HttpUtility.HtmlDecode(encoded);
- }
-
- public static string UrlEncode(this string unEncoded)
- {
- return HttpUtility.UrlEncode(unEncoded);
- }
-
- public static string UrlDecode(this string encoded)
- {
- return HttpUtility.UrlDecode(encoded);
- }
-
/// <summary>
/// Formats a multi-line string for display on the web
/// </summary>
View
138 src/FubuCore/UrlContext.cs
@@ -1,138 +0,0 @@
-using System;
-using System.Linq;
-using System.Web;
-using System.Web.Hosting;
-
-namespace FubuCore
-{
- public static class UrlContext
- {
- static UrlContext()
- {
- Reset();
- }
-
- private static Func<string, string, string> _combine { get; set; }
- private static Func<string, string> _toAbsolute { get; set; }
- private static Func<string, bool> _isAbsolute { get; set; }
- private static Func<string, string> _mapPath { get; set; }
-
- public static void Reset()
- {
- if (HttpRuntime.AppDomainAppVirtualPath != null)
- {
- Live();
- return;
- }
-
- Stub("");
- }
-
- public static void Stub()
- {
- Stub("");
- }
-
- public static void Stub(string usingFakeUrl)
- {
- _combine = (basePath, subPath) =>
- {
- var root = basePath.TrimEnd('/');
- if (root.Length > 0) root += '/';
- return root + subPath.TrimStart('/');
- };
- _isAbsolute = path => path.StartsWith("/");
- _toAbsolute = path => _isAbsolute(path) ? path : _combine(usingFakeUrl, path.Replace("~", ""));
- _mapPath = virtPath => _toAbsolute(virtPath).Replace("~", "").Replace("//", "/").Replace("/", "\\");
- }
-
- public static void Live()
- {
- _combine = VirtualPathUtility.Combine;
- _toAbsolute = VirtualPathUtility.ToAbsolute;
- _isAbsolute = VirtualPathUtility.IsAbsolute;
- _mapPath = HostingEnvironment.MapPath;
- }
-
- public static string ToAbsoluteUrl(this string url)
- {
- if (Uri.IsWellFormedUriString(url, UriKind.Absolute)) return url;
- if (url.IsEmpty()) url = "~/";
- // When running on WebDev.WebServer (and possibly IIS 6) VirtualPathUtility chokes when the url contains a querystring
- var urlParts = url.Split(new[] { '?' }, 2);
- var baseUrl = urlParts[0];
- if (!_isAbsolute(baseUrl))
- {
- baseUrl = _combine("~", baseUrl);
- }
-
- var absoluteUrl = _toAbsolute(baseUrl);
- if (urlParts.Length > 1) absoluteUrl += ("?" + urlParts[1]);
- return absoluteUrl;
- }
-
-
-
- public static string ToPhysicalPath(this string webRelativePath)
- {
- if (!_isAbsolute(webRelativePath))
- {
- webRelativePath = _combine("~", webRelativePath);
- }
- return _mapPath(webRelativePath);
- }
-
- public static string WithQueryStringValues(this string querystring, params object[] values)
- {
- return querystring.ToFormat(values.Select(value => value.ToString().UrlEncoded()).ToArray());
- }
-
- }
-
- public static class UrlStringExtensions
- {
- public static string ToAbsoluteUrl(this string url, string applicationUrl)
- {
- if (!Uri.IsWellFormedUriString(applicationUrl, UriKind.Absolute))
- {
- throw new ArgumentOutOfRangeException("applicationUrl", "applicationUrl must be an absolute url");
- }
-
- url = url ?? string.Empty;
- url = url.TrimStart('~', '/').TrimStart('/');
-
- if (Uri.IsWellFormedUriString(url, UriKind.Absolute)) return url;
-
- return (applicationUrl.TrimEnd('/') + "/" + url).TrimEnd('/');
- }
-
- public static string ToServerQualifiedUrl(this string relativeUrl, string serverBasedUrl)
- {
- var baseUri = new Uri(serverBasedUrl);
- return new Uri(baseUri, relativeUrl.ToAbsoluteUrl(serverBasedUrl)).ToString();
- }
-
- public static string UrlEncoded(this object target)
- {
- //properly encoding URI: http://blogs.msdn.com/yangxind/default.aspx
- return target != null ? Uri.EscapeDataString(target.ToString()) : string.Empty;
- }
-
- public static string WithQueryStringValues(this string querystring, params object[] values)
- {
- return querystring.ToFormat(values.Select(value => value.ToString().UrlEncoded()).ToArray());
- }
-
- public static string WithoutQueryString(this string querystring)
- {
- var questionMarkIndex = querystring.IndexOf('?');
-
- if (questionMarkIndex == -1) return querystring;
-
- return querystring.Substring(0, questionMarkIndex);
- }
-
-
- }
-
-}
Please sign in to comment.
Something went wrong with that request. Please try again.