Testing removal of control characters - issue #1211 and more...

This commit is contained in:
niksedk 2015-08-31 20:33:40 +02:00
parent 54bfba83d2
commit 020e95c5b2
3 changed files with 29 additions and 5 deletions

View File

@ -162,5 +162,28 @@ namespace Nikse.SubtitleEdit.Core
}
return false;
}
public static string RemoveControlCharacters(this string s)
{
var sb = new StringBuilder(s.Length);
foreach (var ch in s)
{
if (!Char.IsControl(ch))
sb.Append(ch);
}
return sb.ToString();
}
public static string RemoveControlCharactersButWhiteSpace(this string s)
{
var sb = new StringBuilder(s.Length);
foreach (var ch in s)
{
if (!Char.IsControl(ch) || ch == '\u000d' || ch == '\u000a' || ch == '\u0009')
sb.Append(ch);
}
return sb.ToString();
}
}
}

View File

@ -42,7 +42,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var xml = new XmlDocument { XmlResolver = null };
try
{
xml.LoadXml(xmlAsString);
xml.LoadXml(xmlAsString.RemoveControlCharactersButWhiteSpace());
var nsmgr = new XmlNamespaceManager(xml.NameTable);
nsmgr.AddNamespace("ttaf1", xml.DocumentElement.NamespaceURI);
@ -152,7 +152,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var sb = new StringBuilder();
lines.ForEach(line => sb.AppendLine(line));
var xml = new XmlDocument { XmlResolver = null };
xml.LoadXml(sb.ToString().Trim().Replace("http://www.w3.org/2006/04/ttaf1#styling\"xml:lang", "http://www.w3.org/2006/04/ttaf1#styling\" xml:lang"));
xml.LoadXml(sb.ToString().RemoveControlCharactersButWhiteSpace().Trim().Replace("http://www.w3.org/2006/04/ttaf1#styling\"xml:lang", "http://www.w3.org/2006/04/ttaf1#styling\" xml:lang"));
var nsmgr = new XmlNamespaceManager(xml.NameTable);
nsmgr.AddNamespace("ttaf1", xml.DocumentElement.NamespaceURI);

View File

@ -124,7 +124,8 @@ namespace Nikse.SubtitleEdit.Forms
private void ButtonAddClick(object sender, EventArgs e)
{
if (textBoxFind.Text.Length > 0)
string findText = textBoxFind.Text.RemoveControlCharacters();
if (findText.Length > 0)
{
string searchType = SearchTypeNormal;
if (radioButtonCaseSensitive.Checked)
@ -132,7 +133,7 @@ namespace Nikse.SubtitleEdit.Forms
else if (radioButtonRegEx.Checked)
{
searchType = SearchTypeRegularExpression;
if (!Utilities.IsValidRegex(textBoxFind.Text))
if (!Utilities.IsValidRegex(findText))
{
MessageBox.Show(Configuration.Settings.Language.General.RegularExpressionIsNotValid);
textBoxFind.Select();
@ -140,7 +141,7 @@ namespace Nikse.SubtitleEdit.Forms
}
}
AddToReplaceListView(true, textBoxFind.Text, textBoxReplace.Text, EnglishSearchTypeToLocal(searchType));
AddToReplaceListView(true, findText, textBoxReplace.Text.RemoveControlCharacters(), EnglishSearchTypeToLocal(searchType));
textBoxFind.Text = string.Empty;
textBoxReplace.Text = string.Empty;
GeneratePreview();