Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ private const val CALENDAR_DATE_QUERY = "date"
private const val LOCAL_DATE_LENGTH = 10

/** Resolve a calendar date from the public app-link contract without accepting malformed input. */
internal fun calendarDateFromUri(uri: Uri): LocalDate? = parseCalendarDateDeepLink(
scheme = uri.scheme,
host = uri.host,
path = uri.path,
queryDate = uri.getQueryParameter(CALENDAR_DATE_QUERY),
)
internal fun calendarDateFromUri(uri: Uri): LocalDate? {
// The activity is exported, so explicit intents can carry any URI. Query accessors throw on
// opaque URIs such as `solidtime:calendar`, which would otherwise crash the activity.
if (!uri.isHierarchical) return null
return parseCalendarDateDeepLink(
scheme = uri.scheme,
host = uri.host,
path = uri.path,
queryDate = uri.getQueryParameter(CALENDAR_DATE_QUERY),
)
}

/**
* Pure parser seam for JVM tests. Both `solidtime://calendar?date=yyyy-MM-dd` and
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package dev.tricked.solidverdant.ui.navigation

import android.net.Uri
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import java.time.LocalDate

@RunWith(RobolectricTestRunner::class)
class CalendarDeepLinkUriTest {

@Test
fun resolvesHierarchicalCalendarLinks() {
assertEquals(LocalDate.of(2026, 8, 11), calendarDateFromUri(Uri.parse("solidtime://calendar?date=2026-08-11")))
assertEquals(LocalDate.of(2026, 8, 11), calendarDateFromUri(Uri.parse("solidtime://calendar/2026-08-11")))
}

@Test
fun ignoresOpaqueUrisInsteadOfThrowing() {
assertNull(calendarDateFromUri(Uri.parse("solidtime:calendar?date=2026-08-11")))
assertNull(calendarDateFromUri(Uri.parse("mailto:someone@example.com")))
}
}
Loading