[Repo Assist] improve: SettingsData.FromJson null safety + GatewayUrlHelper static array#148
Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
Conversation
…array
Two small coding improvements:
1. SettingsData.FromJson(string? json) — null/empty guard
- Change parameter from non-nullable 'string' to 'string?'
- Return null immediately for null or empty input rather than
forwarding to JsonSerializer.Deserialize which would throw
ArgumentNullException (not caught by the existing JsonException
handler)
- Adds two regression tests: null and empty string both return null
2. GatewayUrlHelper.RemoveUserInfo — static readonly char array
- Replace the inline 'new[] { '/', '?', '#' }' array literal
in RemoveUserInfo with a 'private static readonly' field
- The method is called on every URL normalisation and display
sanitisation; the previous form allocated a new char array on
each call, which is now eliminated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
16 tasks
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.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Two small, independent coding improvements to
SettingsDataandGatewayUrlHelper.1.
SettingsData.FromJson— null/empty input safetyProblem:
FromJsondeclared its parameter asstring json(non-nullable). If a caller passesnull(e.g. from NRT-unaware code or a test),JsonSerializer.DeserializethrowsArgumentNullException, which is not caught by the existingJsonExceptionhandler — the exception would propagate unexpectedly.Fix: Change the parameter to
string? jsonand returnnullimmediately for null or empty input, consistent with the method's existing contract of returningnullfor invalid input.Two regression tests added (
nulland""both returnnull).2.
GatewayUrlHelper.RemoveUserInfo— eliminate per-call char array allocationProblem:
RemoveUserInfocontained an inline array literal:This allocates a new
char[]on the heap every time the method is called.RemoveUserInfois called from bothTryNormalizeWebSocketUrlandSanitizeForDisplay, which are invoked on every connection attempt and every URL-related UI update.Fix: Extract to a
private static readonlyfield:The allocation is now paid once at class initialisation rather than once per call.
Test Status
OpenClaw.Shared.TestsOpenClaw.Tray.TestsAll tests pass. No production logic was changed — only defensive input handling and a minor allocation improvement.