Fix crash in "Fix Common Errors" - thx casperlhj :)

Fix  #7061
This commit is contained in:
niksedk 2023-07-15 10:13:26 +02:00
parent 32f8f1ff1a
commit b99adfff5c
2 changed files with 28 additions and 19 deletions

View File

@ -1722,63 +1722,63 @@ namespace Test.FixCommonErrors
public void FixEllipsesStartNormal1()
{
var result = Helper.FixEllipsesStartHelper("...But that is true.");
Assert.AreEqual(result, "But that is true.");
Assert.AreEqual("But that is true.", result);
}
[TestMethod]
public void FixEllipsesStartNormal2()
{
var result = Helper.FixEllipsesStartHelper("... But that is true.");
Assert.AreEqual(result, "But that is true.");
Assert.AreEqual("But that is true.", result);
}
[TestMethod]
public void FixEllipsesStartNormal3()
{
var result = Helper.FixEllipsesStartHelper("Kurt: ... true but bad.");
Assert.AreEqual(result, "Kurt: true but bad.");
Assert.AreEqual("Kurt: true but bad.", result);
}
[TestMethod]
public void FixEllipsesStartNormal4()
{
var result = Helper.FixEllipsesStartHelper("Kurt: ... true but bad.");
Assert.AreEqual(result, "Kurt: true but bad.");
Assert.AreEqual("Kurt: true but bad.", result);
}
[TestMethod]
public void FixEllipsesStartItalic1()
{
var result = Helper.FixEllipsesStartHelper("<i>...But that is true.</i>");
Assert.AreEqual(result, "<i>But that is true.</i>");
Assert.AreEqual("<i>But that is true.</i>", result);
}
[TestMethod]
public void FixEllipsesStartItalic2()
{
var result = Helper.FixEllipsesStartHelper("<i>... But that is true.</i>");
Assert.AreEqual(result, "<i>But that is true.</i>");
Assert.AreEqual("<i>But that is true.</i>", result);
}
[TestMethod]
public void FixEllipsesStartItalic3()
{
var result = Helper.FixEllipsesStartHelper("<i>Kurt: ... true but bad.</i>");
Assert.AreEqual(result, "<i>Kurt: true but bad.</i>");
Assert.AreEqual("<i>Kurt: true but bad.</i>", result);
}
[TestMethod]
public void FixEllipsesStartItalic4()
{
var result = Helper.FixEllipsesStartHelper("<i>Kurt: ... true but bad.</i>");
Assert.AreEqual(result, "<i>Kurt: true but bad.</i>");
Assert.AreEqual("<i>Kurt: true but bad.</i>", result);
}
[TestMethod]
public void FixEllipsesStartItalic5()
{
var result = Helper.FixEllipsesStartHelper("WOMAN 2: <i>...24 hours a day at BabyC.</i>");
Assert.AreEqual(result, "WOMAN 2: <i>24 hours a day at BabyC.</i>");
Assert.AreEqual("WOMAN 2: <i>24 hours a day at BabyC.</i>", result);
}
@ -1786,7 +1786,7 @@ namespace Test.FixCommonErrors
public void FixEllipsesStartItalic6()
{
var result = Helper.FixEllipsesStartHelper("{\\i1}...But that is true.{\\i0}");
Assert.AreEqual(result, "{\\i1}But that is true.{\\i0}");
Assert.AreEqual("{\\i1}But that is true.{\\i0}", result);
}
@ -1794,21 +1794,21 @@ namespace Test.FixCommonErrors
public void FixEllipsesStartFont1()
{
var result = Helper.FixEllipsesStartHelper("<font color=\"#000000\">... true but bad.</font>");
Assert.AreEqual(result, "<font color=\"#000000\">true but bad.</font>");
Assert.AreEqual("<font color=\"#000000\">true but bad.</font>", result);
}
[TestMethod]
public void FixEllipsesStartFont2()
{
var result = Helper.FixEllipsesStartHelper("<font color=\"#000000\"><i>Kurt: ... true but bad.</i></font>");
Assert.AreEqual(result, "<font color=\"#000000\"><i>Kurt: true but bad.</i></font>");
Assert.AreEqual("<font color=\"#000000\"><i>Kurt: true but bad.</i></font>", result);
}
[TestMethod]
public void FixEllipsesStartFont3()
{
var result = Helper.FixEllipsesStartHelper("<i><font color=\"#000000\">Kurt: ...true but bad.</font></i>");
Assert.AreEqual(result, "<i><font color=\"#000000\">Kurt: true but bad.</font></i>");
Assert.AreEqual("<i><font color=\"#000000\">Kurt: true but bad.</font></i>", result);
}
[TestMethod]
@ -1817,7 +1817,7 @@ namespace Test.FixCommonErrors
var actual = "\"...Foobar\"";
const string expected = "\"Foobar\"";
actual = Helper.FixEllipsesStartHelper(actual);
Assert.AreEqual(actual, expected);
Assert.AreEqual(expected, actual);
}
[TestMethod]
@ -1826,7 +1826,7 @@ namespace Test.FixCommonErrors
var actual = "\"... Foobar\"";
const string expected = "\"Foobar\"";
actual = Helper.FixEllipsesStartHelper(actual);
Assert.AreEqual(actual, expected);
Assert.AreEqual(expected, actual);
}
[TestMethod]
@ -1835,15 +1835,23 @@ namespace Test.FixCommonErrors
var actual = "\" . . . Foobar\"";
const string expected = "\"Foobar\"";
actual = Helper.FixEllipsesStartHelper(actual);
Assert.AreEqual(actual, expected);
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void FixEllipsesStartDontChange()
public void FixEllipsesStartDoNotChange()
{
const string input = "- I...";
string actual = Helper.FixEllipsesStartHelper(input);
Assert.AreEqual(actual, input);
Assert.AreEqual(input, actual);
}
[TestMethod]
public void FixEllipsesAfterAssaTag()
{
const string input = "{\\alskdjf}..... Yo";
string actual = Helper.FixEllipsesStartHelper(input);
Assert.AreEqual("{\\alskdjf}Yo", actual);
}
#endregion Ellipses start

View File

@ -114,7 +114,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
text = tag + text.Substring(tagPlusPeriod.Length);
while (text.StartsWith(tag + ".", StringComparison.Ordinal) || text.StartsWith(tag + " ", StringComparison.Ordinal))
{
text = tag + text.Substring(tagPlusPeriod.Length + 1);
text = text.Remove(tag.Length, 1);
}
}
}
@ -184,6 +184,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
text = FixEllipsesStartHelper(text);
pre += " ";
}
return pre + text;
}