Skip to content

Commit

Permalink
Topic/remove default string maniplulaot (#2424)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MrHinsh authored Oct 4, 2024
2 parents af279b1 + f468908 commit 91b3f14
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
10 changes: 1 addition & 9 deletions appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,7 @@
"StringManipulatorTool": {
"Enabled": true,
"MaxStringLength": 1000000,
"Manipulators": [
{
"$type": "RegexStringManipulator",
"Enabled": true,
"Pattern": "[^( -~)\n\r\t]+",
"Replacement": "",
"Description": "Remove invalid characters from the end of the string"
}
]
"Manipulators": []
},
"TfsUserMappingTool": {
"Enabled": false,
Expand Down
17 changes: 14 additions & 3 deletions src/MigrationTools/Tools/StringManipulatorTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ public void ProcessorExecutionWithFieldItem(IProcessor processor, FieldItem fiel
}
if (fieldItem.FieldType == "String" && fieldItem.Value != null)
{
if (HasManipulators())
if (!HasManipulators())
{
foreach (var manipulator in Options.Manipulators)
AddDefaultManipulator();
}
foreach (var manipulator in Options.Manipulators)
{
if (manipulator.Enabled)
{
Expand All @@ -49,7 +51,7 @@ public void ProcessorExecutionWithFieldItem(IProcessor processor, FieldItem fiel
Log.LogDebug("{WorkItemProcessorEnricher}::ProcessorExecutionWithFieldItem::Disabled::{Description}", GetType().Name, manipulator.Description);
}
}
}

if (HasStringTooLong(fieldItem))
{
fieldItem.Value = fieldItem.Value.ToString().Substring(0, Math.Min(fieldItem.Value.ToString().Length, Options.MaxStringLength));
Expand All @@ -58,6 +60,15 @@ public void ProcessorExecutionWithFieldItem(IProcessor processor, FieldItem fiel

}

private void AddDefaultManipulator()
{
if (Options.Manipulators == null)
{
Options.Manipulators = new List<RegexStringManipulator>();
}
Options.Manipulators.Add(new RegexStringManipulator() { Enabled = true, Description = "Default: Removes invalid chars!", Pattern = "[^( -~)\n\r\t]+", Replacement = "" });
}

private bool HasStringTooLong(FieldItem fieldItem)
{
return fieldItem.Value.ToString().Length > 0 && fieldItem.Value.ToString().Length > Options.MaxStringLength;
Expand Down

0 comments on commit 91b3f14

Please sign in to comment.