Skip to content

Commit

Permalink
Refactor getGpxFileName (sanitize file name)
Browse files Browse the repository at this point in the history
  • Loading branch information
RZR-UA committed Dec 2, 2024
1 parent a2cb935 commit ffca910
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
14 changes: 13 additions & 1 deletion OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,20 @@ public String getRouteId() {
return routeId;
}

@NonNull
public String getGpxFileName() {
return !Algorithms.isEmpty(title) ? title : routeId;
String gpxFileName = !Algorithms.isEmpty(title) ? title : routeId;
if (gpxFileName != null) {
return gpxFileName
.replace('/', '_')
.replace('\'', '_')
.replace('\"', '_')
.replace('\r', '_')
.replace('\n', '_');
} else {
LOG.error("Empty travel article in " + this.file);
return "Travel Article File"; // @NonNull
}
}

public String getRouteSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,13 +733,7 @@ public void openTrackMenu(@NonNull TravelArticle article, @NonNull MapActivity m
@NonNull
@Override
public String getGPXName(@NonNull TravelArticle article) {
return article.getGpxFileName()
.replace('/', '_')
.replace('\'', '_')
.replace('\"', '_')
.replace('\r', '_')
.replace('\n', '_')
+ GPX_FILE_EXT;
return article.getGpxFileName() + GPX_FILE_EXT;
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1069,13 +1069,7 @@ public ArrayList<String> getArticleLangs(@NonNull TravelArticleIdentifier articl
@NonNull
@Override
public String getGPXName(@NonNull TravelArticle article) {
return article.getGpxFileName()
.replace('/', '_')
.replace('\'', '_')
.replace('\"', '_')
.replace('\r', '_')
.replace('\n', '_')
+ GPX_FILE_EXT;
return article.getGpxFileName() + GPX_FILE_EXT;
}

@NonNull
Expand Down

0 comments on commit ffca910

Please sign in to comment.