Skip to content

Conversation

@graycreate
Copy link
Member

Summary

  • Fixed incorrect parsing of consecutive sign-in days that was extracting all digits from the HTML string
  • Now correctly extracts only the number before "天" (days) using regex pattern matching
  • Added comprehensive unit tests for various edge cases

Problem

The getCheckinDays() method was using Utils.extractDigits() which extracts ALL digits from the string. When the HTML contained user IDs, dates, or other numbers, they would all be concatenated, resulting in displays like "21612902025091812天" instead of the actual consecutive days count.

Solution

  • Use regex pattern (\\d+)\\s*天 to specifically match numbers followed by "天"
  • Maintain backward compatibility with fallback to extractDigits() for unexpected formats
  • Added unit tests covering various scenarios including strings with dates and user IDs

Test plan

  • Run unit tests: ./gradlew testDebugUnitTest
  • Build debug APK: ./gradlew assembleDebug
  • Test on physical device (Pixel 8)
  • Verify sign-in days display correctly in the app

🤖 Generated with Claude Code

Previously, the extractDigits() method extracted all digits from the string,
causing incorrect display when the string contained user IDs or dates.
Now uses regex to specifically extract the number before "天" (days).

This fixes the issue where sign-in days displayed incorrectly as
"21612902025091812天" instead of the actual consecutive days count.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings September 18, 2025 14:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Fixes the incorrect parsing of consecutive sign-in days by replacing the generic digit extraction method with a targeted regex pattern that specifically matches numbers followed by "天" (days). This prevents the concatenation of unrelated numbers like user IDs and dates that were appearing in the HTML string.

  • Implemented regex pattern (\d+)\s*天 to extract only the number before "天"
  • Added fallback to the original extractDigits() method for backward compatibility
  • Created comprehensive unit tests covering various edge cases including strings with dates and user IDs

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
app/src/main/java/me/ghui/v2er/network/bean/DailyInfo.java Updated getCheckinDays() method with regex-based parsing and fallback logic
app/src/test/java/me/ghui/v2er/network/bean/DailyInfoTest.java Added unit tests for various parsing scenarios including edge cases

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 57 to 65
// Use reflection or make the field package-private in actual implementation
try {
java.lang.reflect.Field field = me.ghui.v2er.network.bean.DailyInfo.class.getDeclaredField("continuousLoginDayStr");
field.setAccessible(true);
field.set(this, continuousLoginDayStr);
} catch (Exception e) {
e.printStackTrace();
}
return super.getCheckinDays();
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

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

Using reflection to access private fields in unit tests creates brittle tests that are tightly coupled to implementation details. Consider making the continuousLoginDayStr field package-private in the actual DailyInfo class or adding a constructor/setter for testing purposes.

Suggested change
// Use reflection or make the field package-private in actual implementation
try {
java.lang.reflect.Field field = me.ghui.v2er.network.bean.DailyInfo.class.getDeclaredField("continuousLoginDayStr");
field.setAccessible(true);
field.set(this, continuousLoginDayStr);
} catch (Exception e) {
e.printStackTrace();
}
return super.getCheckinDays();
// Use the shadowed field directly for testing
if (continuousLoginDayStr == null || continuousLoginDayStr.isEmpty()) {
return "";
}
// Extract the first number before "天"
java.util.regex.Matcher matcher = java.util.regex.Pattern.compile("(\\d+)\\s*天").matcher(continuousLoginDayStr);
if (matcher.find()) {
return matcher.group(1);
}
return "";

Copilot uses AI. Check for mistakes.
field.setAccessible(true);
field.set(this, continuousLoginDayStr);
} catch (Exception e) {
e.printStackTrace();
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

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

Catching generic Exception and only printing the stack trace can hide test failures. Consider catching specific exceptions and using fail() with a descriptive message or rethrowing the exception to make test failures more explicit.

Suggested change
e.printStackTrace();
fail("Reflection failed in test helper: " + e);

Copilot uses AI. Check for mistakes.
- Use specific exception types instead of generic Exception
- Throw RuntimeException instead of just printing stack trace to make test failures explicit
- Improves test maintainability and failure debugging

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@graycreate graycreate merged commit b2b64ad into main Sep 18, 2025
5 checks passed
@graycreate graycreate deleted the bugfix/signin-days-parsing branch September 18, 2025 15:09
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