-
Notifications
You must be signed in to change notification settings - Fork 47
fix: correct parsing of consecutive sign-in days #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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>
There was a problem hiding this 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.
| // 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(); |
Copilot
AI
Sep 18, 2025
There was a problem hiding this comment.
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.
| // 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 ""; |
| field.setAccessible(true); | ||
| field.set(this, continuousLoginDayStr); | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); |
Copilot
AI
Sep 18, 2025
There was a problem hiding this comment.
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.
| e.printStackTrace(); | |
| fail("Reflection failed in test helper: " + e); |
- 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>
Summary
Problem
The
getCheckinDays()method was usingUtils.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
(\\d+)\\s*天to specifically match numbers followed by "天"extractDigits()for unexpected formatsTest plan
./gradlew testDebugUnitTest./gradlew assembleDebug🤖 Generated with Claude Code