Replace assert() with exceptions for release-mode safety#30
Merged
Harry-Chen merged 1 commit intonfcim:masterfrom Mar 13, 2026
Merged
Replace assert() with exceptions for release-mode safety#30Harry-Chen merged 1 commit intonfcim:masterfrom
Harry-Chen merged 1 commit intonfcim:masterfrom
Conversation
assert() statements are stripped in Dart release builds, meaning all NDEF flag validation (MB, ME, CF) and TNF/type-length checks silently disappear in production. Replaced with FormatException for malformed NDEF data and RangeError for invalid TNF values, so errors are caught regardless of build mode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
assert()statements inndef.dartandrecord.dartare stripped in Dart release builds, silently disabling all NDEF flag validation (MB, ME, CF) and TNF/type-length checks in productionFormatExceptionfor malformed NDEF data (invalid flags, wrong type lengths)RangeErrorfor invalid TNF values inNDEFRecordFlags.encode()Files changed
lib/ndef.dart-- MB/ME/CF flag validation indecodeRawNdefMessage()lib/record.dart-- TNF range check inNDEFRecordFlags.encode(), type/id/payload length checks indecodeStream()Test plan
dart compile exe), decoding malformed NDEF data now correctly throws instead of silently accepting it