mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 11:57:29 +01:00
Rejects additional urls with %20 and fixes Wss ones.
This commit is contained in:
@@ -87,7 +87,7 @@ class RelayUrlNormalizer {
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
fun fix(url: String): String? {
|
||||
if (url.length < 4) return null
|
||||
if (url.contains("%00")) return null
|
||||
if (url.contains("%00") || url.contains("%20")) return null
|
||||
|
||||
if (url.length > 50) {
|
||||
// removes multiple urls in the same line
|
||||
@@ -138,9 +138,14 @@ class RelayUrlNormalizer {
|
||||
return "wss://${trimmed.drop(6)}"
|
||||
}
|
||||
|
||||
// fast for good ww:// urls
|
||||
if (trimmed.startsWith("Wss://")) {
|
||||
return "wss://${trimmed.drop(6)}"
|
||||
}
|
||||
|
||||
if (trimmed.contains("://")) {
|
||||
// some other scheme we cannot connect to.
|
||||
Log.w("RelayUrlNormalizer", "Rejected relay URL: $url")
|
||||
Log.w("RelayUrlNormalizer", "Rejected $url")
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -173,14 +178,14 @@ class RelayUrlNormalizer {
|
||||
normalizedUrls.put(url, NormalizationResult.Success(normalized))
|
||||
normalized
|
||||
} else {
|
||||
Log.w("NormalizedRelayUrl", "Rejected Error $url")
|
||||
Log.w("NormalizedRelayUrl", "Rejected $url")
|
||||
normalizedUrls.put(url, NormalizationResult.Error)
|
||||
null
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
if (e is CancellationException) throw e
|
||||
normalizedUrls.put(url, NormalizationResult.Error)
|
||||
Log.w("NormalizedRelayUrl", "Rejected Error $url")
|
||||
Log.w("NormalizedRelayUrl", "Rejected $url")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ package com.vitorpamplona.quartz.nip01Core.relay
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNull
|
||||
|
||||
class RelayUrlFormatterTest {
|
||||
@Test
|
||||
@@ -43,5 +44,12 @@ class RelayUrlFormatterTest {
|
||||
assertEquals("ws://a.onion/", RelayUrlNormalizer.normalizeOrNull("a.onion/")?.url)
|
||||
|
||||
assertEquals("wss://nostr.mom/", RelayUrlNormalizer.normalizeOrNull("wss://nostr.mom")?.url)
|
||||
|
||||
assertEquals("wss://relay.nostr.band/", RelayUrlNormalizer.normalizeOrNull("Wss://relay.nostr.band")?.url)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun weirdRelay() {
|
||||
assertNull(RelayUrlNormalizer.normalizeOrNull("wss://relay%20list%20to%20discover%20the%20user's%20content"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user