Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/AngleSharp.Diffing.Tests/DiffBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,17 @@ public void Test006(string control, string test)

diffs.ShouldBeEmpty();
}

[Theory(DisplayName = "When a control element has 'class:ignore', elements with and without class should return empty diffs")]
[InlineData("<div class=\"ian-fleming\"></div>")]
[InlineData("<div class=\"\"></div>")]
[InlineData("<div class></div>")]
[InlineData("<div></div>")]
public void Test007(string testHtml)
{
var controlHtml = "<div class:ignore></div>";
var diffs = DiffBuilder.Compare(controlHtml).WithTest(testHtml).Build();
Assert.Empty(diffs);
}

}
9 changes: 8 additions & 1 deletion src/AngleSharp.Diffing/Core/HtmlDifferenceEngine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AngleSharp.Diffing.Core.Diffs;
using AngleSharp.Diffing.Strategies.AttributeStrategies;

namespace AngleSharp.Diffing.Core;

Expand Down Expand Up @@ -160,7 +161,13 @@ void MarkSelectedSourcesAsMatched(in AttributeComparison comparison)

void UpdateUnmatchedTracking()
{
Context.MissingAttributeSources.AddRange(controls.GetUnmatched());
// Filter out unmatched :ignore attributes, they were meant to be ignored after all
// https://github.com/AngleSharp/AngleSharp.Diffing/issues/48
var controlsUnmatched = controls
.GetUnmatched()
.Where(c => !IgnoreAttributeComparer.IsIgnoreAttribute(c.Attribute));

Context.MissingAttributeSources.AddRange(controlsUnmatched);
Context.UnexpectedAttributeSources.AddRange(tests.GetUnmatched());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/AngleSharp.Diffing/Core/SourceMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public IEnumerable<AttributeComparisonSource> GetUnmatched()
{
foreach (var source in _sources.Values)
{
if (!_matched.Contains(source.Attribute.Name))
if (IsUnmatched(source.Attribute.Name))
yield return source;
}
}
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe revert this change?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe merge the two files into one static file, e.g. IgnoreAttributeStrategy.cs, have the Compare and Match methods in the static class, and then have the static IsIgnoreAttribute method there being shared.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to keep IgnoreAttributeComparer for backwards compatibility?

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ public static CompareResult Compare(in AttributeComparison comparison, CompareRe
if (currentDecision.IsSameOrSkip)
return currentDecision;

return comparison.Control.Attribute.Name.EndsWith(DIFF_IGNORE_POSTFIX, StringComparison.OrdinalIgnoreCase)
return IsIgnoreAttribute(comparison.Control.Attribute)
? CompareResult.Same
: currentDecision;
}

public static bool IsIgnoreAttribute(IAttr source)
{
return source.Name.EndsWith(DIFF_IGNORE_POSTFIX, StringComparison.OrdinalIgnoreCase);
}
}
Loading