Skip to content

Commit

Permalink
Added check for a negative width or height value of the rectangle.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Oct 15, 2023
1 parent c480c2b commit 00c6915
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Magick.NET/Types/MagickRectangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ internal sealed partial class MagickRectangle
{
public MagickRectangle(int x, int y, int width, int height)
{
Throw.IfNegative(nameof(width), width);
Throw.IfNegative(nameof(height), height);

X = x;
Y = y;
Width = width;
Expand Down
15 changes: 15 additions & 0 deletions tests/Magick.NET.Tests/MagickImageTests/TheBorderMethod.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

using System;
using ImageMagick;
using Xunit;

Expand All @@ -10,6 +11,20 @@ public partial class MagickImageTests
{
public class TheBorderMethod
{
[Fact]
public void ShouldThrowExceptionWhenWidthIsNegative()
{
using var image = new MagickImage("xc:red", 1, 1);
Assert.Throws<ArgumentException>("width", () => image.Border(-1, 1));
}

[Fact]
public void ShouldThrowExceptionWhenHeightIsNegative()
{
using var image = new MagickImage("xc:red", 1, 1);
Assert.Throws<ArgumentException>("height", () => image.Border(1, -1));
}

[Fact]
public void ShouldAddBorderOnAllSides()
{
Expand Down

0 comments on commit 00c6915

Please sign in to comment.