Trim names and summaries on database insert
When metadata is read from localized files such as Fastlane/Triple-Play the names/summaries get stored on the server with a trailing newline. This is not a problem when displaying as HTML as in a browser but causes unwanted whitespace in the app. See also https://gitlab.com/fdroid/fdroidserver/merge_requests/375, and https://gitlab.com/fdroid/fdroidclient/issues/1114
This commit is contained in:
		
							parent
							
								
									b86723be44
								
							
						
					
					
						commit
						44d984786f
					
				@ -944,6 +944,10 @@ public class AppProvider extends FDroidProvider {
 | 
			
		||||
            values.put(Cols.DESCRIPTION, "");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Trim these to avoid unwanted newlines in the UI
 | 
			
		||||
        values.put(Cols.SUMMARY, values.getAsString(Cols.SUMMARY).trim());
 | 
			
		||||
        values.put(Cols.NAME, values.getAsString(Cols.NAME).trim());
 | 
			
		||||
 | 
			
		||||
        String[] categories = null;
 | 
			
		||||
        boolean saveCategories = false;
 | 
			
		||||
        if (values.containsKey(Cols.ForWriting.Categories.CATEGORIES)) {
 | 
			
		||||
 | 
			
		||||
@ -267,6 +267,16 @@ public class AppProviderTest extends FDroidProviderTest {
 | 
			
		||||
        assertEquals("F-Droid", otherApp.name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testInsertTrimsNamesAndSummary() {
 | 
			
		||||
        // Insert a new record with unwanted newlines...
 | 
			
		||||
        App app = insertApp("org.fdroid.trimmer", "Trim me\n", "Trim me too\n");
 | 
			
		||||
 | 
			
		||||
        assertEquals("org.fdroid.trimmer", app.packageName);
 | 
			
		||||
        assertEquals("Trim me", app.name);
 | 
			
		||||
        assertEquals("Trim me too", app.summary);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * We intentionally throw an IllegalArgumentException if you haven't
 | 
			
		||||
     * yet called cursor.move*().
 | 
			
		||||
@ -296,6 +306,12 @@ public class AppProviderTest extends FDroidProviderTest {
 | 
			
		||||
        insertApp(contentResolver, context, id, name, new ContentValues());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private App insertApp(String id, String name, String summary) {
 | 
			
		||||
        ContentValues additionalValues = new ContentValues();
 | 
			
		||||
        additionalValues.put(Cols.SUMMARY, summary);
 | 
			
		||||
        return insertApp(contentResolver, context, id, name, additionalValues);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static App insertApp(ShadowContentResolver contentResolver, Context context, String id, String name, ContentValues additionalValues) {
 | 
			
		||||
        return insertApp(contentResolver, context, id, name, additionalValues, 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user