Skip to content

Commit

Permalink
Fixed NullReferenceException in LogEventItem.ToString()
Browse files Browse the repository at this point in the history
by assigning an empty collection if Params is null after deserialization.
Some modification to ToString method.
  • Loading branch information
CXuesong committed Aug 15, 2018
1 parent 6afafdf commit 7cf84ed
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions WikiClientLibrary/Generators/LogEventsList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,18 @@ internal static LogEventItem FromRecentChangeItem(RecentChangeItem rc)
public string Action { get; private set; }

/// <summary>For log items, gets additional log parameters.</summary>
[JsonProperty]
public LogParameterCollection Params { get; private set; }
/// <value>
/// The without additional parameters of the log item.
/// For log items without additional parameters available,
/// this is an empty collection.
/// </value>
/// <remarks>
/// For modern MediaWiki builds, this property uses the value of `params` property.
/// For compatibility with MediaWiki 1.19 and below, this property also tries to use the property
/// whose name is the value of <see cref="Type"/>. (e.g. use `move` property if <see cref="Type"/> is <see cref="LogActions.Move"/>.
/// </remarks>
[JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace)]
public LogParameterCollection Params { get; private set; } = LogParameterCollection.Empty;

/// <inheritdoc/>
public override string ToString()
Expand All @@ -283,8 +293,13 @@ public override string ToString()
sb.Append(TimeStamp);
sb.Append(',');
sb.Append(Type);
sb.Append('/');
sb.Append(Action);
if (Type != Action)
{
sb.Append('/');
sb.Append(Action);
}
sb.Append(',');
sb.Append(Title);
sb.Append(",{");
if (Params.Count > 0)
{
Expand All @@ -305,6 +320,13 @@ public override string ToString()
public class LogParameterCollection : WikiReadOnlyDictionary
{

internal static readonly LogParameterCollection Empty = new LogParameterCollection();

static LogParameterCollection()
{
Empty.MakeReadonly();
}

/// <summary>
/// (<see cref="LogActions.Move"/>) Namespace ID of the move target.
/// </summary>
Expand Down

0 comments on commit 7cf84ed

Please sign in to comment.