Fix String replacement for player links inside exported JSON

Issue was the JSON escape adding \/ so the replacer did not find
../player as it was ..\/player instead

Affects issues:
- Fixed #1593
This commit is contained in:
Risto Lahtela 2020-10-25 21:33:15 +02:00
parent b37edf78fc
commit e2043715d2
2 changed files with 9 additions and 3 deletions

View File

@ -32,6 +32,7 @@ import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.file.PlanFiles;
import com.djrapitops.plan.storage.file.Resource;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -143,8 +144,8 @@ public class NetworkPageExporter extends FileExporter {
export(toDirectory.resolve("data").resolve(jsonResourceName),
// Replace ../player in urls to fix player page links
StringUtils.replaceEach(found.get().getAsString(),
new String[]{"../player", "./player"},
new String[]{relativePlayerLink, relativePlayerLink}
new String[]{StringEscapeUtils.escapeJson("../player"), StringEscapeUtils.escapeJson("./player")},
new String[]{StringEscapeUtils.escapeJson(relativePlayerLink), StringEscapeUtils.escapeJson(relativePlayerLink)}
)
);
exportPaths.put("./v1/" + resource, toRelativePathFromRoot("data/" + jsonResourceName));

View File

@ -33,6 +33,7 @@ import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.file.PlanFiles;
import com.djrapitops.plan.storage.file.Resource;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -156,7 +157,11 @@ public class ServerPageExporter extends FileExporter {
export(toDirectory.resolve("data").resolve(jsonResourceName),
// Replace ../player in urls to fix player page links
StringUtils.replace(found.get().getAsString(), "../player", toRelativePathFromRoot("player"))
StringUtils.replace(
found.get().getAsString(),
StringEscapeUtils.escapeJson("../player"),
StringEscapeUtils.escapeJson(toRelativePathFromRoot("player"))
)
);
exportPaths.put("../v1/" + resource, toRelativePathFromRoot("data/" + jsonResourceName));
}