Ejemplo n.º 1
0
        /// <inheritdoc />
        public bool Match(
            HttpContext httpContext,
            IRouter route,
            string routeKey,
            RouteValueDictionary values,
            RouteDirection routeDirection)
        {
            if (routeKey == null)
            {
                throw new ArgumentNullException(nameof(routeKey));
            }

            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            if (values.TryGetValue(routeKey, out var obj) && obj != null)
            {
                var value = Convert.ToString(obj, CultureInfo.InvariantCulture);
                return(!FileNameRouteConstraint.IsFileName(value));
            }

            // No value or null value.
            //
            // We want to return true here because the core use-case of the constraint is to *exclude*
            // things that look like file names. There's nothing here that looks like a file name, so
            // let it through.
            return(true);
        }
Ejemplo n.º 2
0
        public void Match_MissingValue_IsNotFileName()
        {
            // Arrange
            var constraint = new FileNameRouteConstraint();

            var values = new RouteValueDictionary();

            // Act
            var result = constraint.Match(httpContext: null, route: null, "path", values, RouteDirection.IncomingRequest);

            // Assert
            Assert.False(result);
        }
Ejemplo n.º 3
0
        public void Match_RouteValue_IsFileName(object value)
        {
            // Arrange
            var constraint = new FileNameRouteConstraint();

            var values = new RouteValueDictionary();

            values.Add("path", value);

            // Act
            var result = constraint.Match(httpContext: null, route: null, "path", values, RouteDirection.IncomingRequest);

            // Assert
            Assert.True(result);
        }
Ejemplo n.º 4
0
 bool IParameterLiteralNodeMatchingPolicy.MatchesLiteral(string parameterName, string literal)
 {
     return(!FileNameRouteConstraint.IsFileName(literal));
 }