summaryrefslogtreecommitdiff
path: root/external/aspnetwebstack/src/System.Web.WebPages/RequestExtensions.cs
blob: 19ffd9d6515a5fe107a87ac745ea219f57deeee5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.

using System.Diagnostics.CodeAnalysis;

namespace System.Web.WebPages
{
    public static class RequestExtensions
    {
        [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "request", Justification = "The request parameter is no longer being used but we do not want to break legacy callers.")]
        [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "Response.Redirect() takes its URI as a string parameter.")]
        public static bool IsUrlLocalToHost(this HttpRequestBase request, string url)
        {
            return !url.IsEmpty() &&
                   ((url[0] == '/' && (url.Length == 1 || (url[1] != '/' && url[1] != '\\'))) || // "/" or "/foo" but not "//" or "/\"
                    (url.Length > 1 && url[0] == '~' && url[1] == '/')); // "~/" or "~/foo"
        }
    }
}