Skip to content

Commit

Permalink
fix #15543: adapt to gc.com login page change
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiemuc authored and Lineflyer committed Apr 4, 2024
1 parent 62c68bd commit 943d194
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public final class GCConstants {
static final Pattern PATTERN_BACKGROUND_IMAGE = Pattern.compile("<body background=\"(.+?)\"");
static final String PATTERN_GC_CHECKER = "ctl00_ContentBody_lblSolutionChecker";


//Try to find pattern as follows:
//"publicGuid":"abc.def","referenceCode":"PRxyz","id":1234567,"username":"user","dateCreated":"2012-01-21T20:51:14","findCount":15123,
public static final Pattern PATTERN_LOGIN_NAME_CACHE_COUNT = Pattern.compile("\"publicGuid\":\"[^\"]+\",\"referenceCode\":\"[^\"]+\",\"id\":[0-9]+,\"username\":\"([^\"]+)\",\"dateCreated\":\"[0-9:T-]+\",\"findCount\":([0-9]+),");

// Info box top-right
public static final Pattern PATTERN_LOGIN_NAME = Pattern.compile("\\swindow(?>\\.|\\[')(?:headerSettings|chromeSettings)(?>'\\])?\\s*=\\s*\\{[\\S\\s]*\"username\":\\s*\"([^\"]*)\",?[\\S\\s]*\\}");
/**
Expand Down
10 changes: 8 additions & 2 deletions main/src/main/java/cgeo/geocaching/connector/gc/GCParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,13 @@ static boolean ignoreCache(@NonNull final Geocache cache) {

@Nullable
public static String getUsername(@NonNull final String page) {
final String username = TextUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME, null);
String username = TextUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME_CACHE_COUNT, null);
if (StringUtils.isNotBlank(username)) {
return username;
}

//second try
username = TextUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME, null);
if (StringUtils.isNotBlank(username)) {
return username;
}
Expand All @@ -1718,7 +1724,7 @@ public static String getUsername(@NonNull final String page) {
public static int getCachesCount(@Nullable final String page) {
int cachesCount = -1;
try {
final String intStringToParse = removeDotAndComma(TextUtils.getMatch(page, GCConstants.PATTERN_CACHES_FOUND, true, ""));
final String intStringToParse = TextUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME_CACHE_COUNT, true, 2, "", false);
if (!StringUtils.isBlank(intStringToParse)) {
cachesCount = Integer.parseInt(intStringToParse);
}
Expand Down

0 comments on commit 943d194

Please sign in to comment.