Skip to content

Commit

Permalink
Added validation back to the copyright frame.
Browse files Browse the repository at this point in the history
Added some important comments.
  • Loading branch information
JeevanJames committed May 2, 2018
1 parent 9643f7d commit d9bb92d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/Id3.Net/Frames/String/CopyrightFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ public override string ToString()

protected override void ValidateValue(string value)
{
//TODO: Validate
//if (!CopyrightPrefixPattern.IsMatch(value))
// throw new ArgumentException(FrameMessages.Copyright_InvalidFormat, nameof(value));
if (!string.IsNullOrEmpty(value) && !CopyrightPrefixPattern.IsMatch(value))
throw new ArgumentException(FrameMessages.Copyright_InvalidFormat, nameof(value));
}

internal override string TextValue
{
get => base.TextValue;
set => base.TextValue = !string.IsNullOrEmpty(value) && !CopyrightPrefixPattern.IsMatch(value) ? null : value;
}

private static readonly Regex CopyrightPrefixPattern = new Regex(@"^\d{4} ");
Expand Down
11 changes: 11 additions & 0 deletions src/Id3.Net/Frames/TextFrameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ public TValue Value
}
}

/// <summary>
/// Deriving classes can override this method to validate the native value being set.
/// <para />
/// If the value is invalid, the method should throw an exception.
/// </summary>
/// <param name="value">The native value being set.</param>
/// <exception cref="Id3Exception">Thrown if the specified native value is invalid.</exception>
/// <remarks>
/// Note that in a lot of cases, a native value of null or something that translates to an empty string is considered
/// valid. In such cases, the frame may be unassigned, but the value should still be allowed.
/// </remarks>
protected virtual void ValidateValue(TValue value)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/Id3.Net/Mp3/Mp3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public Mp3(byte[] byteStream, Mp3Permissions permissions = Mp3Permissions.Read)
SetupStream(stream, permissions);
}

protected void SetupStream(Stream stream, Mp3Permissions permissions)
private void SetupStream(Stream stream, Mp3Permissions permissions)
{
if (stream == null)
throw new ArgumentNullException(nameof(stream));
Expand Down

0 comments on commit d9bb92d

Please sign in to comment.