public void MatchShouldReturnTrueIfValueForAttributeIsNullAndKeyMatching() { //Arrange var matcher = new AttributeMatcher() { attribute = null, matcher = new EqualToMatcher(DataTypeEnum.NUMBER, 12012), negate = false }; var attributes = new Dictionary <string, object>(); attributes.Add("card_number", 12012); attributes.Add("card_type", "ABC"); //Act var result = matcher.Match(new Key("12012", "12012"), attributes); //Assert Assert.IsTrue(result); }
public MvcHtmlString Parse(IHtmlHelper htmlHelper, string current) { if (string.IsNullOrWhiteSpace(current)) { return(MvcHtmlString.Empty); } current = ShortcodeMatcher.Replace(current, match => { var tagName = match.Groups[1].Value; if (!_renderShortcode.CanRender(tagName)) { return(string.Empty); } var matches = AttributeMatcher.Matches(match.Groups[2].Value); var attributes = matches.Cast <Match>().ToDictionary(m => m.Groups[1].Value, m => m.Groups[2].Value); return(_renderShortcode.Render(htmlHelper, tagName, attributes)); }); return(MvcHtmlString.Create(current)); }
/// <inheritdoc /> public override void Process(TagHelperContext context, TagHelperOutput output) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } // Pass through attribute that is also a well-known HTML attribute. if (Href != null) { output.CopyHtmlAttribute(HrefAttributeName, context); } // If there's no "href" attribute in output.Attributes this will noop. ProcessUrlAttribute(HrefAttributeName, output); // Retrieve the TagHelperOutput variation of the "href" attribute in case other TagHelpers in the // pipeline have touched the value. If the value is already encoded this LinkTagHelper may // not function properly. Href = output.Attributes[HrefAttributeName]?.Value as string; Mode mode; if (!AttributeMatcher.TryDetermineMode(context, ModeDetails, Compare, out mode)) { // No attributes matched so we have nothing to do return; } // NOTE: Values in TagHelperOutput.Attributes may already be HTML-encoded. var attributes = new TagHelperAttributeList(output.Attributes); if (AppendVersion == true) { EnsureFileVersionProvider(); if (Href != null) { output.Attributes[HrefAttributeName].Value = _fileVersionProvider.AddFileVersionToPath(Href); } } var builder = new DefaultTagHelperContent(); if (mode == Mode.GlobbedHref || mode == Mode.Fallback && !string.IsNullOrEmpty(HrefInclude)) { BuildGlobbedLinkTags(attributes, builder); if (string.IsNullOrEmpty(Href)) { // Only HrefInclude is specified. Don't render the original tag. output.TagName = null; output.Content.SetContent(HtmlString.Empty); } } if (mode == Mode.Fallback) { string resolvedUrl; if (TryResolveUrl(FallbackHref, resolvedUrl: out resolvedUrl)) { FallbackHref = resolvedUrl; } BuildFallbackBlock(builder); } output.PostElement.SetContent(builder); }
public virtual bool IsCoveredBy(AttributeMatcher attributeMatcher) { return(false); }
internal NegativeRule(RuleBuilder ruleBuilder, AttributeMatcher attributeMatcher) : base(ruleBuilder) { this.attributeMatcher = attributeMatcher; }
/// <inheritdoc /> public override void Process(TagHelperContext context, TagHelperOutput output) { string resolvedUrl; // Pass through attribute that is also a well-known HTML attribute. if (Src != null) { output.CopyHtmlAttribute(SrcAttributeName, context); if (TryResolveUrl(Src, encodeWebRoot: false, resolvedUrl: out resolvedUrl)) { Src = resolvedUrl; } ProcessUrlAttribute(SrcAttributeName, output); } var modeResult = AttributeMatcher.DetermineMode(context, ModeDetails); modeResult.LogDetails(Logger, this, context.UniqueId, ViewContext.View.Path); if (!modeResult.FullMatches.Any()) { // No attributes matched so we have nothing to do return; } // NOTE: Values in TagHelperOutput.Attributes may already be HTML-encoded. var attributes = new TagHelperAttributeList(output.Attributes); if (AppendVersion == true) { EnsureFileVersionProvider(); var attributeStringValue = output.Attributes[SrcAttributeName]?.Value as string; if (attributeStringValue != null) { output.Attributes[SrcAttributeName].Value = _fileVersionProvider.AddFileVersionToPath(attributeStringValue); } } var builder = new DefaultTagHelperContent(); // Get the highest matched mode var mode = modeResult.FullMatches.Select(match => match.Mode).Max(); if (mode == Mode.GlobbedSrc || mode == Mode.Fallback && !string.IsNullOrEmpty(SrcInclude)) { BuildGlobbedScriptTags(attributes, builder); if (string.IsNullOrEmpty(Src)) { // Only SrcInclude is specified. Don't render the original tag. output.TagName = null; output.Content.SetContent(string.Empty); } } if (mode == Mode.Fallback) { if (TryResolveUrl(FallbackSrc, encodeWebRoot: false, resolvedUrl: out resolvedUrl)) { FallbackSrc = resolvedUrl; } BuildFallbackBlock(attributes, builder); } output.PostElement.SetContent(builder); }
internal PositiveRule(RuleBuilder ruleBuilder, AttributeMatcher keyMatcher, AttributeMatcher valueMatcher) : base(ruleBuilder) { this.keyMatcher = keyMatcher; this.valueMatcher = valueMatcher; }
private AttributeMatcher ParseMatcher(ParsedSplit parsedSplit, MatcherDefinition matcherDefinition) { if (matcherDefinition.matcherType == null) { throw new Exception("Missing matcher type value"); } var matcherType = matcherDefinition.matcherType; IMatcher matcher = null; try { MatcherTypeEnum result; var isValidMatcherType = Enum.TryParse(matcherType, out result); if (isValidMatcherType) { switch (result) { case MatcherTypeEnum.ALL_KEYS: matcher = GetAllKeysMatcher(); break; case MatcherTypeEnum.BETWEEN: matcher = GetBetweenMatcher(matcherDefinition); break; case MatcherTypeEnum.EQUAL_TO: matcher = GetEqualToMatcher(matcherDefinition); break; case MatcherTypeEnum.GREATER_THAN_OR_EQUAL_TO: matcher = GetGreaterThanOrEqualToMatcher(matcherDefinition); break; case MatcherTypeEnum.IN_SEGMENT: matcher = GetInSegmentMatcher(matcherDefinition, parsedSplit); break; case MatcherTypeEnum.LESS_THAN_OR_EQUAL_TO: matcher = GetLessThanOrEqualToMatcher(matcherDefinition); break; case MatcherTypeEnum.WHITELIST: matcher = GetWhitelistMatcher(matcherDefinition); break; case MatcherTypeEnum.EQUAL_TO_SET: matcher = GetEqualToSetMatcher(matcherDefinition); break; case MatcherTypeEnum.CONTAINS_ANY_OF_SET: matcher = GetContainsAnyOfSetMatcher(matcherDefinition); break; case MatcherTypeEnum.CONTAINS_ALL_OF_SET: matcher = GetContainsAllOfSetMatcher(matcherDefinition); break; case MatcherTypeEnum.PART_OF_SET: matcher = GetPartOfSetMatcher(matcherDefinition); break; case MatcherTypeEnum.STARTS_WITH: matcher = GetStartsWithMatcher(matcherDefinition); break; case MatcherTypeEnum.ENDS_WITH: matcher = GetEndsWithMatcher(matcherDefinition); break; case MatcherTypeEnum.CONTAINS_STRING: matcher = GetContainsStringMatcher(matcherDefinition); break; case MatcherTypeEnum.IN_SPLIT_TREATMENT: matcher = GetDependencyMatcher(matcherDefinition); break; case MatcherTypeEnum.EQUAL_TO_BOOLEAN: matcher = GetEqualToBooleanMatcher(matcherDefinition); break; case MatcherTypeEnum.MATCHES_STRING: matcher = GetMatchesStringMatcher(matcherDefinition); break; } } } catch (Exception e) { Log.Error("Error parsing matcher", e); } if (matcher == null) { throw new Exception(string.Format("Unable to create matcher for matcher type: {0}", matcherType)); } AttributeMatcher attributeMatcher = new AttributeMatcher() { matcher = matcher, negate = matcherDefinition.negate }; if (matcherDefinition.keySelector != null && matcherDefinition.keySelector.attribute != null) { attributeMatcher.attribute = matcherDefinition.keySelector.attribute; } return(attributeMatcher); }
/// <inheritdoc /> public override void Process(TagHelperContext context, TagHelperOutput output) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } // Pass through attribute that is also a well-known HTML attribute. if (Src != null) { output.CopyHtmlAttribute(SrcAttributeName, context); } // If there's no "src" attribute in output.Attributes this will noop. ProcessUrlAttribute(SrcAttributeName, output); // Retrieve the TagHelperOutput variation of the "src" attribute in case other TagHelpers in the // pipeline have touched the value. If the value is already encoded this ScriptTagHelper may // not function properly. Src = output.Attributes[SrcAttributeName]?.Value as string; if (!AttributeMatcher.TryDetermineMode(context, ModeDetails, Compare, out var mode)) { // No attributes matched so we have nothing to do return; } if (AppendVersion == true) { EnsureFileVersionProvider(); if (Src != null) { var index = output.Attributes.IndexOfName(SrcAttributeName); var existingAttribute = output.Attributes[index]; output.Attributes[index] = new TagHelperAttribute( existingAttribute.Name, FileVersionProvider.AddFileVersionToPath(ViewContext.HttpContext.Request.PathBase, Src), existingAttribute.ValueStyle); } } var builder = output.PostElement; builder.Clear(); if (mode == Mode.GlobbedSrc || mode == Mode.Fallback && !string.IsNullOrEmpty(SrcInclude)) { BuildGlobbedScriptTags(output.Attributes, builder); if (string.IsNullOrEmpty(Src)) { // Only SrcInclude is specified. Don't render the original tag. output.TagName = null; output.Content.SetContent(string.Empty); } } if (mode == Mode.Fallback) { if (TryResolveUrl(FallbackSrc, resolvedUrl: out string resolvedUrl)) { FallbackSrc = resolvedUrl; } BuildFallbackBlock(output.Attributes, builder); } }
public bool IsCoveredBy(AttributeMatcher attributeMatcher) { return(attributeMatcher == this); }
/// <inheritdoc /> public override void Process(TagHelperContext context, TagHelperOutput output) { string resolvedUrl; // Pass through attribute that is also a well-known HTML attribute. if (Href != null) { output.CopyHtmlAttribute(HrefAttributeName, context); } // If there's no "href" attribute in output.Attributes this will noop. ProcessUrlAttribute(HrefAttributeName, output); // Retrieve the TagHelperOutput variation of the "href" attribute in case other TagHelpers in the // pipeline have touched the value. If the value is already encoded this LinkTagHelper may // not function properly. Href = output.Attributes[HrefAttributeName]?.Value as string; var modeResult = AttributeMatcher.DetermineMode(context, ModeDetails); modeResult.LogDetails(Logger, this, context.UniqueId, ViewContext.View.Path); if (!modeResult.FullMatches.Any()) { // No attributes matched so we have nothing to do return; } // NOTE: Values in TagHelperOutput.Attributes may already be HTML-encoded. var attributes = new TagHelperAttributeList(output.Attributes); if (AppendVersion == true) { EnsureFileVersionProvider(); if (Href != null) { output.Attributes[HrefAttributeName].Value = _fileVersionProvider.AddFileVersionToPath(Href); } } var builder = new DefaultTagHelperContent(); // Get the highest matched mode var mode = modeResult.FullMatches.Select(match => match.Mode).Max(); if (mode == Mode.GlobbedHref || mode == Mode.Fallback && !string.IsNullOrEmpty(HrefInclude)) { BuildGlobbedLinkTags(attributes, builder); if (string.IsNullOrEmpty(Href)) { // Only HrefInclude is specified. Don't render the original tag. output.TagName = null; output.Content.SetContent(HtmlString.Empty); } } if (mode == Mode.Fallback) { if (TryResolveUrl(FallbackHref, encodeWebRoot: false, resolvedUrl: out resolvedUrl)) { FallbackHref = resolvedUrl; } BuildFallbackBlock(builder); } output.PostElement.SetContent(builder); }