Skip to content

Commit 91b3f14

Browse files
authored
Topic/remove default string maniplulaot (#2424)
Working with @xci-mrt to identify why StringManipulatorTool is removing danish chars even when he adds a new manipulator... Turns out the default and the new one are merged. So both run regardless of the desirement. I have moved the default manipultor to code and it will only present if the manipulators list is empty. this allows an override. Closes #2424
2 parents af279b1 + f468908 commit 91b3f14

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

appsettings.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,7 @@
150150
"StringManipulatorTool": {
151151
"Enabled": true,
152152
"MaxStringLength": 1000000,
153-
"Manipulators": [
154-
{
155-
"$type": "RegexStringManipulator",
156-
"Enabled": true,
157-
"Pattern": "[^( -~)\n\r\t]+",
158-
"Replacement": "",
159-
"Description": "Remove invalid characters from the end of the string"
160-
}
161-
]
153+
"Manipulators": []
162154
},
163155
"TfsUserMappingTool": {
164156
"Enabled": false,

src/MigrationTools/Tools/StringManipulatorTool.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ public void ProcessorExecutionWithFieldItem(IProcessor processor, FieldItem fiel
3434
}
3535
if (fieldItem.FieldType == "String" && fieldItem.Value != null)
3636
{
37-
if (HasManipulators())
37+
if (!HasManipulators())
3838
{
39-
foreach (var manipulator in Options.Manipulators)
39+
AddDefaultManipulator();
40+
}
41+
foreach (var manipulator in Options.Manipulators)
4042
{
4143
if (manipulator.Enabled)
4244
{
@@ -49,7 +51,7 @@ public void ProcessorExecutionWithFieldItem(IProcessor processor, FieldItem fiel
4951
Log.LogDebug("{WorkItemProcessorEnricher}::ProcessorExecutionWithFieldItem::Disabled::{Description}", GetType().Name, manipulator.Description);
5052
}
5153
}
52-
}
54+
5355
if (HasStringTooLong(fieldItem))
5456
{
5557
fieldItem.Value = fieldItem.Value.ToString().Substring(0, Math.Min(fieldItem.Value.ToString().Length, Options.MaxStringLength));
@@ -58,6 +60,15 @@ public void ProcessorExecutionWithFieldItem(IProcessor processor, FieldItem fiel
5860

5961
}
6062

63+
private void AddDefaultManipulator()
64+
{
65+
if (Options.Manipulators == null)
66+
{
67+
Options.Manipulators = new List<RegexStringManipulator>();
68+
}
69+
Options.Manipulators.Add(new RegexStringManipulator() { Enabled = true, Description = "Default: Removes invalid chars!", Pattern = "[^( -~)\n\r\t]+", Replacement = "" });
70+
}
71+
6172
private bool HasStringTooLong(FieldItem fieldItem)
6273
{
6374
return fieldItem.Value.ToString().Length > 0 && fieldItem.Value.ToString().Length > Options.MaxStringLength;

0 commit comments

Comments
 (0)