Skip to content

refactor: replace regex JSON parsing with DataContractJsonSerializer#40

Merged
hieuck merged 1 commit into
mainfrom
feature/replace-regex-json-parsing
Jul 8, 2026
Merged

refactor: replace regex JSON parsing with DataContractJsonSerializer#40
hieuck merged 1 commit into
mainfrom
feature/replace-regex-json-parsing

Conversation

@hieuck

@hieuck hieuck commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary\r\nReplace the fragile regex-based extraction of release tags with proper JSON deserialization.\r\n\r\n## Changes\r\n- Add DTO with .\r\n- Use to parse the GitHub releases API response.\r\n- This serializer is built into .NET Framework 4.8, so no new external dependencies are required.\r\n- Preserve existing fallback: invalid or empty responses yield no tags.\r\n\r\n## Tests\r\n- MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file. passes: 58/58.\r\n\r\nCloses #36.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@hieuck, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 31 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 05132ed6-3f1c-401a-99d7-6912b753d74f

📥 Commits

Reviewing files that changed from the base of the PR and between 6a03da1 and b34b742.

📒 Files selected for processing (2)
  • src/KeePassAutoReload.csproj
  • src/UpdateChecker.cs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/replace-regex-json-parsing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread src/UpdateChecker.cs
Comment on lines +222 to 225
catch
{
if (match.Success) values.Add(Regex.Unescape(match.Groups["value"].Value));
return new string[0];
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch block in ExtractVersionTags (lines 222-225) silently swallows all exceptions and returns an empty array. This can obscure the root cause of failures, making debugging difficult if the JSON format changes or network responses are malformed.

Recommendation: At minimum, log the exception or provide a mechanism to surface the error, such as rethrowing or returning an error indicator. For example:

catch (Exception ex)
{
    // Log the exception or rethrow
    // Logger.LogError(ex, "Failed to extract version tags from JSON");
    return new string[0];
}

- Add GitHubRelease DTO and deserialize the GitHub API response properly.

- Use System.Runtime.Serialization.Json.DataContractJsonSerializer (built into .NET Framework 4.8).

- Preserve existing fallback behavior: invalid/empty responses yield no tags.

- Remove Regex using directive.

- dotnet test passes 58/58.

Closes #36.
@hieuck hieuck force-pushed the feature/replace-regex-json-parsing branch from f641293 to b34b742 Compare July 8, 2026 02:01
Comment thread src/UpdateChecker.cs
Comment on lines 118 to 124

cancellationToken.ThrowIfCancellationRequested();
string json = await client.DownloadStringAsync(ReleasesApiUrl, cancellationToken);
string tagName = GetNewestVersionTag(ExtractJsonStrings(json, "tag_name").ToArray());
string tagName = GetNewestVersionTag(ExtractVersionTags(json));

UpdateInfo info = new UpdateInfo();
info.LatestVersion = tagName;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential Issue: Lack of Validation for tagName in UpdateInfo Construction

The code assigns tagName directly to UpdateInfo.LatestVersion and uses it to build URLs without validating that it is non-null and well-formed. If ExtractVersionTags or GetNewestVersionTag returns an empty or malformed string, this could result in broken URLs or incorrect update status.

Recommendation: Add validation for tagName before constructing URLs and setting IsUpdateAvailable. For example:

if (string.IsNullOrEmpty(tagName)) {
    // Handle the error, e.g., return null or a default UpdateInfo indicating no update
}

This will prevent propagating invalid data and improve robustness.

@hieuck hieuck merged commit fa80e32 into main Jul 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant