diff --git a/app/src/main/java/org/fdroid/fdroid/RepoXMLHandler.java b/app/src/main/java/org/fdroid/fdroid/RepoXMLHandler.java index 0b1fc1a9b..0e3ac2e8b 100644 --- a/app/src/main/java/org/fdroid/fdroid/RepoXMLHandler.java +++ b/app/src/main/java/org/fdroid/fdroid/RepoXMLHandler.java @@ -203,7 +203,7 @@ public class RepoXMLHandler extends DefaultHandler { break; case "desc": // New-style description. - curapp.description = str; + curapp.description = App.formatDescription(str); break; case "summary": curapp.summary = str; diff --git a/app/src/main/java/org/fdroid/fdroid/data/App.java b/app/src/main/java/org/fdroid/fdroid/data/App.java index 19c883f25..a6d2430b0 100644 --- a/app/src/main/java/org/fdroid/fdroid/data/App.java +++ b/app/src/main/java/org/fdroid/fdroid/data/App.java @@ -382,6 +382,16 @@ public class App extends ValueObject implements Comparable, Parcelable { initApkFromApkFile(context, this.installedApk, packageInfo, apkFile); } + /** + * In order to format all in coming descriptions before they are written + * out to the database and used elsewhere, this is needed to intercept + * the setting of {@link App#description} to insert the format method. + */ + @JsonProperty("description") + private void setDescription(String description) { // NOPMD + this.description = formatDescription(description); + } + /** * Parses the {@code localized} block in the incoming index metadata, * choosing the best match in terms of locale/language while filling as @@ -499,7 +509,7 @@ public class App extends ValueObject implements Comparable, Parcelable { } value = getLocalizedEntry(localized, localesToUse, "description"); if (!TextUtils.isEmpty(value)) { - description = value; + description = formatDescription(value); } featureGraphic = getLocalizedGraphicsEntry(localized, localesToUse, "featureGraphic"); @@ -583,6 +593,13 @@ public class App extends ValueObject implements Comparable, Parcelable { return new String[0]; } + /** + * Returns the app description text with all newlines replaced by {@code
} + */ + public static String formatDescription(String description) { + return description.replace("\n", "
"); + } + public String getFeatureGraphicUrl(Context context) { if (TextUtils.isEmpty(featureGraphic)) { return null;