Refactor SDP parsing to use Span<T> and StringBuilder#1655
Merged
Conversation
Replaced Regex and string.Split with Span-based parsing for SDP lines and attributes. Updated ToString methods to use StringBuilder, reducing allocations and improving performance. Standardized string comparisons and improved parsing robustness. Changes applied across SDP, media format, connection, and security description classes for better efficiency and maintainability.
sipsorcery
approved these changes
Jun 1, 2026
sipsorcery
added a commit
that referenced
this pull request
Jun 1, 2026
#1658) * Add SDP parsing regression tests for malformed crypto and rtpmap lines Adds regression tests asserting the desired SDP parser behaviour for recognised-but-invalid lines: - a crypto line with a whitespace-only value -> TryParse returns false - a crypto line missing the crypto-suite field -> TryParse returns false - a crypto line missing key parameters -> TryParse returns false - an rtpmap attribute with a non-numeric payload ID is dropped (not round-tripped): it produces no media format entry, does not corrupt the valid formats, and is not re-emitted by ToString(). These encode the intended behaviour delivered by #1655. They are expected to fail against the current master parser (which throws an IndexOutOfRangeException on the malformed crypto lines and round-trips the invalid rtpmap line) and to pass once #1655 lands. Tests only; no production code changes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Potential fix for pull request finding 'Missed 'readonly' opportunity' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Draft
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.
Replaced Regex and string.Split with Span-based parsing for SDP lines and attributes. Updated ToString methods to use StringBuilder, reducing allocations and improving performance. Standardized string comparisons and improved parsing robustness. Changes applied across SDP, media format, connection, and security description classes for better efficiency and maintainability.
Split of #1639