change square brackets to round ones in manifest name
This commit is contained in:
parent
5a0d337fcf
commit
a7f03abe25
|
@ -12,6 +12,7 @@
|
||||||
* Fixed update alert shown for a prerelease version on GitHub if it's not marked as prerelease.
|
* Fixed update alert shown for a prerelease version on GitHub if it's not marked as prerelease.
|
||||||
|
|
||||||
* For mod authors:
|
* For mod authors:
|
||||||
|
* SMAPI now treats square brackets in the manifest `Name` field as round brackets, to avoid breaking tools which parse log files.
|
||||||
* Updated to [FluentHttpClient](https://github.com/Pathoschild/FluentHttpClient#readme) 4.2.0 (see [changes](https://github.com/Pathoschild/FluentHttpClient/blob/develop/RELEASE-NOTES.md#420)).
|
* Updated to [FluentHttpClient](https://github.com/Pathoschild/FluentHttpClient#readme) 4.2.0 (see [changes](https://github.com/Pathoschild/FluentHttpClient/blob/develop/RELEASE-NOTES.md#420)).
|
||||||
|
|
||||||
## 3.16.2
|
## 3.16.2
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Text;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using StardewModdingAPI.Toolkit.Serialization.Converters;
|
using StardewModdingAPI.Toolkit.Serialization.Converters;
|
||||||
|
|
||||||
|
@ -90,13 +91,13 @@ namespace StardewModdingAPI.Toolkit.Serialization.Models
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public Manifest(string uniqueId, string name, string author, string description, ISemanticVersion version, ISemanticVersion? minimumApiVersion, string? entryDll, IManifestContentPackFor? contentPackFor, IManifestDependency[]? dependencies, string[]? updateKeys)
|
public Manifest(string uniqueId, string name, string author, string description, ISemanticVersion version, ISemanticVersion? minimumApiVersion, string? entryDll, IManifestContentPackFor? contentPackFor, IManifestDependency[]? dependencies, string[]? updateKeys)
|
||||||
{
|
{
|
||||||
this.UniqueID = this.NormalizeWhitespace(uniqueId);
|
this.UniqueID = this.NormalizeField(uniqueId);
|
||||||
this.Name = this.NormalizeWhitespace(name);
|
this.Name = this.NormalizeField(name, replaceSquareBrackets: true);
|
||||||
this.Author = this.NormalizeWhitespace(author);
|
this.Author = this.NormalizeField(author);
|
||||||
this.Description = this.NormalizeWhitespace(description);
|
this.Description = this.NormalizeField(description);
|
||||||
this.Version = version;
|
this.Version = version;
|
||||||
this.MinimumApiVersion = minimumApiVersion;
|
this.MinimumApiVersion = minimumApiVersion;
|
||||||
this.EntryDll = this.NormalizeWhitespace(entryDll);
|
this.EntryDll = this.NormalizeField(entryDll);
|
||||||
this.ContentPackFor = contentPackFor;
|
this.ContentPackFor = contentPackFor;
|
||||||
this.Dependencies = dependencies ?? Array.Empty<IManifestDependency>();
|
this.Dependencies = dependencies ?? Array.Empty<IManifestDependency>();
|
||||||
this.UpdateKeys = updateKeys ?? Array.Empty<string>();
|
this.UpdateKeys = updateKeys ?? Array.Empty<string>();
|
||||||
|
@ -113,17 +114,47 @@ namespace StardewModdingAPI.Toolkit.Serialization.Models
|
||||||
/*********
|
/*********
|
||||||
** Private methods
|
** Private methods
|
||||||
*********/
|
*********/
|
||||||
/// <summary>Normalize whitespace in a raw string.</summary>
|
/// <summary>Normalize a manifest field to strip newlines, trim whitespace, and optionally strip square brackets.</summary>
|
||||||
/// <param name="input">The input to strip.</param>
|
/// <param name="input">The input to strip.</param>
|
||||||
|
/// <param name="replaceSquareBrackets">Whether to replace square brackets with round ones. This is used in the mod name to avoid breaking the log format.</param>
|
||||||
#if NET5_0_OR_GREATER
|
#if NET5_0_OR_GREATER
|
||||||
[return: NotNullIfNotNull("input")]
|
[return: NotNullIfNotNull("input")]
|
||||||
#endif
|
#endif
|
||||||
private string? NormalizeWhitespace(string? input)
|
private string? NormalizeField(string? input, bool replaceSquareBrackets = false)
|
||||||
{
|
{
|
||||||
return input
|
input = input?.Trim();
|
||||||
?.Trim()
|
|
||||||
.Replace("\r", "")
|
if (!string.IsNullOrEmpty(input))
|
||||||
.Replace("\n", "");
|
{
|
||||||
|
StringBuilder? builder = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < input.Length; i++)
|
||||||
|
{
|
||||||
|
switch (input[i])
|
||||||
|
{
|
||||||
|
case '\r':
|
||||||
|
case '\n':
|
||||||
|
builder ??= new StringBuilder(input);
|
||||||
|
builder[i] = ' ';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '[' when replaceSquareBrackets:
|
||||||
|
builder ??= new StringBuilder(input);
|
||||||
|
builder[i] = '(';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ']' when replaceSquareBrackets:
|
||||||
|
builder ??= new StringBuilder(input);
|
||||||
|
builder[i] = ')';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (builder != null)
|
||||||
|
input = builder.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return input;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue