logviewer: keep share names with regex punctuation in one Uri segment
- Commit
b1f29e4f41f896c7652d5a24ec823d8282c83ca1- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 20:10 UTC (28 days ago)
- Parents
069325d
Symptom: Share silently failed for logs whose filter regex contained '#', '?' or '/' (all ordinary regex punctuation). The snapshot filename embeds the title, and the title embeds the filter text, so e.g. filtering on 'a#b' produced the blob name 'System log | a#b <uuid>.txt'. Root cause: BlobProvider.getUri built the content Uri with Uri.Builder.path(name). path() interprets the string as a whole path: '#' begins a fragment and '/' splits segments. The Uri a share target resolves back has a different path than the one the entry was cached under, entryFor() missed, and openFile threw FileNotFoundException; query() likewise found nothing, so the share sheet could not even name the blob. Fix: appendPath(name), which appends the name as a single encoded segment. lastPathSegment decodes it back to the full display name. Regression: BlobProviderTest gains a round-trip case with a name containing '#', '?' and '/'; it failed before (query found no entry) and passes now. BlobProviderTest + LogViewerViewModelTest (share path) green.
Diff
logviewer/src/main/java/com/vayunmathur/logviewer/provider/BlobProvider.kt
diff --git a/logviewer/src/main/java/com/vayunmathur/logviewer/provider/BlobProvider.kt b/logviewer/src/main/java/com/vayunmathur/logviewer/provider/BlobProvider.ktindex 7cd0c70908..37b728b979 100644--- a/logviewer/src/main/java/com/vayunmathur/logviewer/provider/BlobProvider.kt+++ b/logviewer/src/main/java/com/vayunmathur/logviewer/provider/BlobProvider.kt@@ -131,10 +131,15 @@ class BlobProvider : ContentProvider(), ContentProvider.PipeDataWriter<ByteArray * Compressed as it is written, so the uncompressed log never exists as one array. */ fun getUri(blobName: String, write: (OutputStream) -> Unit): Uri {+ // appendPath, not path: the name is one segment, and it embeds the title -+ // which embeds the user's filter regex. path() would let a '#' start a+ // fragment, a '?' a query and a '/' extra segments, so the Uri the share+ // target hands back would no longer key the entry (and the display name+ // would be only the last fragment of the name). val uri = Uri.Builder() .scheme(ContentResolver.SCHEME_CONTENT) .authority(AUTHORITY)- .path(blobName)+ .appendPath(blobName) .build() val compressed = ByteArrayOutputStream()
logviewer/src/test/java/com/vayunmathur/logviewer/provider/BlobProviderTest.kt
diff --git a/logviewer/src/test/java/com/vayunmathur/logviewer/provider/BlobProviderTest.kt b/logviewer/src/test/java/com/vayunmathur/logviewer/provider/BlobProviderTest.ktindex a99f85e14f..b6ed7ce23f 100644--- a/logviewer/src/test/java/com/vayunmathur/logviewer/provider/BlobProviderTest.kt+++ b/logviewer/src/test/java/com/vayunmathur/logviewer/provider/BlobProviderTest.kt@@ -68,6 +68,21 @@ class BlobProviderTest { } } + @Test+ fun `getUri round-trips a name with uri-special characters`() {+ // Snapshot names embed the title, which embeds the user's filter regex:+ // '#', '?' and '/' must not fracture the Uri or the display name.+ val name = "System log | a#b?c/d e1.txt"+ val uri = BlobProvider.getUri(name) { it.write("data".toByteArray()) }+ val cursor = resolver.query(uri, null, null, null, null)+ assertNotNull(cursor)+ cursor.use {+ assertTrue(it.moveToFirst())+ assertEquals(name, it.getString(it.getColumnIndex(OpenableColumns.DISPLAY_NAME)))+ assertEquals(4L, it.getLong(it.getColumnIndex(OpenableColumns.SIZE)))+ }+ }+ @Test fun `getUri counts single-byte writes toward the size`() { val uri = BlobProvider.getUri("bytes.txt") { out ->