Skip to content

Commit 949310e

Browse files
committed
Fix failing test
1 parent 5707f0b commit 949310e

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/HtmlDiff/HtmlDiff.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ public class HtmlDiff
3030
{"</sub>",0},
3131
{"</sup>",0},
3232
{"</strike>",0},
33-
{"</s>",0}
33+
{"</s>",0},
34+
{"</span>", 0}
3435
};
3536

3637
private static readonly Regex SpecialCaseOpeningTagRegex = new Regex(
37-
"<((strong)|(b)|(i)|(em)|(big)|(small)|(u)|(sub)|(sup)|(strike)|(s))[\\>\\s]+", RegexOptions.Compiled | RegexOptions.IgnoreCase);
38+
"<((strong)|(b)|(i)|(em)|(big)|(small)|(u)|(sub)|(sup)|(strike)|(s)|(span))[\\>\\s]+", RegexOptions.Compiled | RegexOptions.IgnoreCase);
3839

3940

4041
/// <summary>
@@ -268,7 +269,7 @@ private void InsertTag(string tag, string cssClass, List<string> words)
268269
var openingTag = _specialTagDiffStack.Count == 0 ? null : _specialTagDiffStack.Pop();
269270

270271
// If we didn't have an opening tag, and we don't have a match with the previous tag used
271-
if (openingTag == null || openingTag != words.Last().Replace("/", ""))
272+
if (openingTag == null || Utils.GetTagName(openingTag) != Utils.GetTagName(words.Last()))
272273
{
273274
// do nothing
274275
}

src/HtmlDiff/Utils.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System;
2+
using System.Linq;
23
using System.Text.RegularExpressions;
34

45
namespace HtmlDiff
@@ -10,6 +11,7 @@ public static class Utils
1011
private static Regex tagWordRegex = new Regex(@"<[^\s>]+", RegexOptions.Compiled);
1112
private static Regex whitespaceRegex = new Regex("^(\\s|&nbsp;)+$", RegexOptions.Compiled);
1213
private static Regex wordRegex = new Regex(@"[\w\#@]+", RegexOptions.Compiled | RegexOptions.ECMAScript);
14+
private static Regex tagRegex = new Regex(@"\s*</?(?<name>[^\s>]+)[^>]*>\s*", RegexOptions.Compiled);
1315

1416
private static readonly string[] SpecialCaseWordTags = { "<img" };
1517

@@ -84,5 +86,16 @@ public static bool IsWord(char text)
8486
{
8587
return wordRegex.IsMatch(new string(new[] { text }));
8688
}
89+
90+
public static string GetTagName(string word)
91+
{
92+
var match = tagRegex.Match(word);
93+
94+
// returns empty string if it's not a tag
95+
if (!match.Success)
96+
return string.Empty;
97+
98+
return match.Groups["name"].Value.ToLower();
99+
}
87100
}
88101
}

0 commit comments

Comments
 (0)