mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-14 22:37:41 +01:00
Compare commits
2 Commits
ws
...
bug/1149-A
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e208e0f6bf | ||
|
|
f18c2ce324 |
@@ -10,28 +10,22 @@ namespace WireMock.Serialization;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates sanitized file names for mappings
|
/// Creates sanitized file names for mappings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MappingFileNameSanitizer
|
internal class MappingFileNameSanitizer
|
||||||
{
|
{
|
||||||
|
private const string SpaceChar = " ";
|
||||||
private const char ReplaceChar = '_';
|
private const char ReplaceChar = '_';
|
||||||
|
|
||||||
private readonly WireMockServerSettings _settings;
|
|
||||||
|
|
||||||
public MappingFileNameSanitizer(WireMockServerSettings settings)
|
|
||||||
{
|
|
||||||
_settings = Guard.NotNull(settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates sanitized file names for mappings
|
/// Creates sanitized file names for mappings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string BuildSanitizedFileName(IMapping mapping)
|
public string BuildSanitizedFileName(IMapping mapping, ProxyAndRecordSettings? proxyAndRecordSettings)
|
||||||
{
|
{
|
||||||
string name;
|
string name;
|
||||||
if (!string.IsNullOrEmpty(mapping.Title))
|
if (!string.IsNullOrEmpty(mapping.Title))
|
||||||
{
|
{
|
||||||
// remove 'Proxy Mapping for ' and an extra space character after the HTTP request method
|
// remove 'Proxy Mapping for ' and an extra space character after the HTTP request method
|
||||||
name = mapping.Title.Replace(ProxyAndRecordSettings.DefaultPrefixForSavedMappingFile, "").Replace(' '.ToString(), string.Empty);
|
name = mapping.Title!.Replace(ProxyAndRecordSettings.DefaultPrefixForSavedMappingFile, string.Empty).Replace(SpaceChar, string.Empty);
|
||||||
if (_settings.ProxyAndRecordSettings?.AppendGuidToSavedMappingFile == true)
|
if (proxyAndRecordSettings?.AppendGuidToSavedMappingFile == true)
|
||||||
{
|
{
|
||||||
name += $"{ReplaceChar}{mapping.Guid}";
|
name += $"{ReplaceChar}{mapping.Guid}";
|
||||||
}
|
}
|
||||||
@@ -41,10 +35,11 @@ public class MappingFileNameSanitizer
|
|||||||
name = mapping.Guid.ToString();
|
name = mapping.Guid.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(_settings.ProxyAndRecordSettings?.PrefixForSavedMappingFile))
|
if (!string.IsNullOrEmpty(proxyAndRecordSettings?.PrefixForSavedMappingFile))
|
||||||
{
|
{
|
||||||
name = $"{_settings.ProxyAndRecordSettings.PrefixForSavedMappingFile}{ReplaceChar}{name}";
|
name = $"{proxyAndRecordSettings.PrefixForSavedMappingFile}{ReplaceChar}{name}";
|
||||||
}
|
}
|
||||||
|
|
||||||
return $"{Path.GetInvalidFileNameChars().Aggregate(name, (current, c) => current.Replace(c, ReplaceChar))}.json";
|
return $"{Path.GetInvalidFileNameChars().Aggregate(name, (current, c) => current.Replace(c, ReplaceChar))}.json";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user