Fixes non http uris in the references tag
This commit is contained in:
+7
-1
@@ -52,6 +52,12 @@ class ReferenceTag {
|
|||||||
|
|
||||||
fun assemble(url: String) = arrayOf(TAG_NAME, HttpUrlFormatter.normalize(url))
|
fun assemble(url: String) = arrayOf(TAG_NAME, HttpUrlFormatter.normalize(url))
|
||||||
|
|
||||||
fun assemble(urls: List<String>): List<Array<String>> = urls.mapTo(HashSet()) { HttpUrlFormatter.normalize(it) }.map { arrayOf(TAG_NAME, it) }
|
fun assemble(urls: List<String>): List<Array<String>> =
|
||||||
|
urls
|
||||||
|
.mapTo(HashSet()) {
|
||||||
|
HttpUrlFormatter.normalize(it)
|
||||||
|
}.map {
|
||||||
|
arrayOf(TAG_NAME, it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,15 +20,25 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.quartz.nip10Notes.content
|
package com.vitorpamplona.quartz.nip10Notes.content
|
||||||
|
|
||||||
import com.vitorpamplona.quartz.nip01Core.tags.references.HttpUrlFormatter
|
import com.vitorpamplona.quartz.utils.DualCase
|
||||||
import com.vitorpamplona.quartz.utils.fastFindURLs
|
import com.vitorpamplona.quartz.utils.startsWithAny
|
||||||
|
import com.vitorpamplona.quartz.utils.urldetector.detection.UrlDetector
|
||||||
|
|
||||||
fun findURLs(text: String) = fastFindURLs(text)
|
val rejectSchemes =
|
||||||
|
listOf(
|
||||||
|
DualCase("ftp:"),
|
||||||
|
DualCase("ftps:"),
|
||||||
|
DualCase("ws:"),
|
||||||
|
DualCase("wss:"),
|
||||||
|
DualCase("nostr:"),
|
||||||
|
DualCase("blossom:"),
|
||||||
|
)
|
||||||
|
|
||||||
fun buildUrlRefs(urls: List<String>): List<Array<String>> =
|
fun findURLs(text: String) =
|
||||||
urls
|
UrlDetector(text).detect().mapNotNull {
|
||||||
.mapTo(HashSet()) { url ->
|
if (it.originalUrl.startsWithAny(rejectSchemes)) {
|
||||||
HttpUrlFormatter.normalize(url)
|
null
|
||||||
}.map {
|
} else {
|
||||||
arrayOf("r", it)
|
it.originalUrl
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2025 Vitor Pamplona
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to use,
|
|
||||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
|
||||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
||||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package com.vitorpamplona.quartz.utils
|
|
||||||
|
|
||||||
expect fun fastFindURLs(text: String): List<String>
|
|
||||||
+2
-3
@@ -21,7 +21,6 @@
|
|||||||
package com.vitorpamplona.quartz.nip10Notes.urls
|
package com.vitorpamplona.quartz.nip10Notes.urls
|
||||||
|
|
||||||
import com.vitorpamplona.quartz.nip10Notes.content.findURLs
|
import com.vitorpamplona.quartz.nip10Notes.content.findURLs
|
||||||
import com.vitorpamplona.quartz.utils.fastFindURLs
|
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertContains
|
import kotlin.test.assertContains
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
@@ -31,7 +30,7 @@ class UrlsDetectorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun detectUrlNumber() {
|
fun detectUrlNumber() {
|
||||||
val detectedLinks = fastFindURLs(testSentence)
|
val detectedLinks = findURLs(testSentence)
|
||||||
assertEquals(2, detectedLinks.size)
|
assertEquals(2, detectedLinks.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +47,7 @@ class UrlsDetectorTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
fun doesNotCrashOnJapaneseText() {
|
fun doesNotCrashOnJapaneseText() {
|
||||||
val detectedLinks = fastFindURLs("今北産業")
|
val detectedLinks = findURLs("今北産業")
|
||||||
assertEquals(0, detectedLinks.size)
|
assertEquals(0, detectedLinks.size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2025 Vitor Pamplona
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to use,
|
|
||||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
|
||||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
||||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package com.vitorpamplona.quartz.utils
|
|
||||||
|
|
||||||
import kotlinx.cinterop.ExperimentalForeignApi
|
|
||||||
import swiftbridge.UrlDetector
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
@OptIn(ExperimentalForeignApi::class)
|
|
||||||
actual fun fastFindURLs(text: String): List<String> {
|
|
||||||
val detectorInstance = UrlDetector()
|
|
||||||
return detectorInstance.findURLsWithText(text) as List<String>
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2025 Vitor Pamplona
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to use,
|
|
||||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
|
||||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
||||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package com.vitorpamplona.quartz.utils
|
|
||||||
|
|
||||||
import com.vitorpamplona.quartz.utils.urldetector.detection.UrlDetector
|
|
||||||
|
|
||||||
actual fun fastFindURLs(text: String): List<String> = UrlDetector(text).detect().map { it.originalUrl }
|
|
||||||
Reference in New Issue
Block a user