Skip to content

Commit

Permalink
Merge pull request #41 from PinguApps/40-bug-null-data-can-cause-a-crash
Browse files Browse the repository at this point in the history
Added handling for null data
  • Loading branch information
pingu2k4 authored Feb 25, 2024
2 parents 1109a2a + 9339546 commit a92a41a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/PinguApps.Blazor.QRCode/QRCode.razor
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@

void GenerateQR()
{
var qr = QrCode.EncodeText(Data, GetEcc);
var qr = QrCode.EncodeText(Data ?? "", GetEcc);
var path = qr.ToGraphicsPath(PaddingCells);
var viewboxSize = qr.Size + PaddingCells * 2;

Expand Down
16 changes: 16 additions & 0 deletions tests/PinguApps.Blazor.QRCode.Tests/QRCodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,20 @@ public async Task DataSnapshots(string data)
settings.UseParameters(data);
await Verify(component.Find("path").GetAttribute("d"), settings);
}

[Fact]
public void AvoidsCrashWhenDataNull()
{
// Arrange
using var context = new TestContext();

// Act
var exception = Record.Exception(() =>
{
var component = context.RenderComponent<QRCode>(parameters => parameters.Add(p => p.Data, null));
});

// Assert
Assert.Null(exception);
}
}

0 comments on commit a92a41a

Please sign in to comment.