Switches to our own version of the Url Detector
This commit is contained in:
+3
-2
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip64Chess
|
||||
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip64Chess.game.ChessGameEvent
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
@@ -83,7 +84,7 @@ class ChessGameEventTest {
|
||||
sig = "test_sig",
|
||||
)
|
||||
|
||||
assertEquals(customAltText, testEvent.altText(), "Alt text should be extractable from tags")
|
||||
assertEquals(customAltText, testEvent.alt(), "Alt text should be extractable from tags")
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,7 +99,7 @@ class ChessGameEventTest {
|
||||
sig = "test_sig",
|
||||
)
|
||||
|
||||
assertEquals(null, testEvent.altText(), "Should return null when no alt tag present")
|
||||
assertEquals(null, testEvent.alt(), "Should return null when no alt tag present")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+322
@@ -0,0 +1,322 @@
|
||||
/*
|
||||
* 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.urldetector
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class UrlMarkerTest {
|
||||
fun testUrlMarker(
|
||||
testString: String,
|
||||
scheme: String?,
|
||||
username: String?,
|
||||
password: String?,
|
||||
host: String?,
|
||||
port: Int,
|
||||
path: String?,
|
||||
query: String?,
|
||||
fragment: String?,
|
||||
indices: IntArray,
|
||||
) {
|
||||
val urlMarker = UrlMarker()
|
||||
urlMarker.originalUrl = testString
|
||||
urlMarker.setIndices(indices)
|
||||
val url = urlMarker.createUrl()
|
||||
assertEquals(url.host, host, "host, " + testString)
|
||||
assertEquals(url.path, path, "path, " + testString)
|
||||
assertEquals(url.scheme, scheme, "scheme, " + testString)
|
||||
assertEquals(url.username, username, "username, " + testString)
|
||||
assertEquals(url.password, password, "password, " + testString)
|
||||
assertEquals(url.port, port, "port, " + testString)
|
||||
assertEquals(url.query, query, "query, " + testString)
|
||||
assertEquals(url.fragment, fragment, "fragment, " + testString)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test1() =
|
||||
testUrlMarker(
|
||||
"hello@hello.com",
|
||||
"https",
|
||||
"hello",
|
||||
"",
|
||||
"hello.com",
|
||||
443,
|
||||
"/",
|
||||
"",
|
||||
"",
|
||||
intArrayOf(-1, 0, 6, -1, -1, -1, -1),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test2() =
|
||||
testUrlMarker(
|
||||
"http://hello@hello.com",
|
||||
"http",
|
||||
"hello",
|
||||
"",
|
||||
"hello.com",
|
||||
80,
|
||||
"/",
|
||||
"",
|
||||
"",
|
||||
intArrayOf(0, 7, 13, -1, -1, -1, -1),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test3() =
|
||||
testUrlMarker(
|
||||
"hello@hello.com",
|
||||
"https",
|
||||
"hello",
|
||||
"",
|
||||
"hello.com",
|
||||
443,
|
||||
"/",
|
||||
"",
|
||||
"",
|
||||
intArrayOf(-1, 0, 6, -1, -1, -1, -1),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test4() =
|
||||
testUrlMarker(
|
||||
"https://user@google.com/h?hello=w#abc",
|
||||
"https",
|
||||
"user",
|
||||
"",
|
||||
"google.com",
|
||||
443,
|
||||
"/h",
|
||||
"?hello=w",
|
||||
"#abc",
|
||||
intArrayOf(0, 8, 13, -1, 23, 25, 33),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test5() =
|
||||
testUrlMarker(
|
||||
"www.booopp.com:20#fa",
|
||||
"https",
|
||||
"",
|
||||
"",
|
||||
"www.booopp.com",
|
||||
20,
|
||||
"/",
|
||||
"",
|
||||
"#fa",
|
||||
intArrayOf(-1, -1, 0, 15, -1, -1, 17),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test6() =
|
||||
testUrlMarker(
|
||||
"www.yahooo.com:20?fff#aa",
|
||||
"https",
|
||||
"",
|
||||
"",
|
||||
"www.yahooo.com",
|
||||
20,
|
||||
"/",
|
||||
"?fff",
|
||||
"#aa",
|
||||
intArrayOf(-1, -1, 0, 15, -1, 17, 21),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test7() =
|
||||
testUrlMarker(
|
||||
"www.google.com#fa",
|
||||
"https",
|
||||
"",
|
||||
"",
|
||||
"www.google.com",
|
||||
443,
|
||||
"/",
|
||||
"",
|
||||
"#fa",
|
||||
intArrayOf(-1, -1, 0, -1, -1, -1, 14),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test8() =
|
||||
testUrlMarker(
|
||||
"www.google.com?3fd#fa",
|
||||
"https",
|
||||
"",
|
||||
"",
|
||||
"www.google.com",
|
||||
443,
|
||||
"/",
|
||||
"?3fd",
|
||||
"#fa",
|
||||
intArrayOf(-1, -1, 0, -1, -1, 14, 18),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test9() =
|
||||
testUrlMarker(
|
||||
"//www.google.com/",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"www.google.com",
|
||||
-1,
|
||||
"/",
|
||||
"",
|
||||
"",
|
||||
intArrayOf(-1, -1, 2, -1, 16, -1, -1),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test10() =
|
||||
testUrlMarker(
|
||||
"http://www.google.com/",
|
||||
"http",
|
||||
"",
|
||||
"",
|
||||
"www.google.com",
|
||||
80,
|
||||
"/",
|
||||
"",
|
||||
"",
|
||||
intArrayOf(0, -1, 7, -1, 21, -1, -1),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test11() =
|
||||
testUrlMarker(
|
||||
"ftp://whosdere:me@google.com/",
|
||||
"ftp",
|
||||
"whosdere",
|
||||
"me",
|
||||
"google.com",
|
||||
21,
|
||||
"/",
|
||||
"",
|
||||
"",
|
||||
intArrayOf(0, 6, 18, -1, 28, -1, -1),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test12() =
|
||||
testUrlMarker(
|
||||
"ono:doope@fb.net:9090/dhdh",
|
||||
"https",
|
||||
"ono",
|
||||
"doope",
|
||||
"fb.net",
|
||||
9090,
|
||||
"/dhdh",
|
||||
"",
|
||||
"",
|
||||
intArrayOf(-1, 0, 10, 17, 21, -1, -1),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test13() =
|
||||
testUrlMarker(
|
||||
"ono:a@fboo.com:90/dhdh/@1234",
|
||||
"https",
|
||||
"ono",
|
||||
"a",
|
||||
"fboo.com",
|
||||
90,
|
||||
"/dhdh/@1234",
|
||||
"",
|
||||
"",
|
||||
intArrayOf(-1, 0, 6, 15, 17, -1, -1),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test14() =
|
||||
testUrlMarker(
|
||||
"fbeoo.net:990/dhdeh/@1234",
|
||||
"https",
|
||||
"",
|
||||
"",
|
||||
"fbeoo.net",
|
||||
990,
|
||||
"/dhdeh/@1234",
|
||||
"",
|
||||
"",
|
||||
intArrayOf(-1, -1, 0, 10, 13, -1, -1),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test15() =
|
||||
testUrlMarker(
|
||||
"fbeoo:@boop.com/dhdeh/@1234?aj=r",
|
||||
"https",
|
||||
"fbeoo",
|
||||
"",
|
||||
"boop.com",
|
||||
443,
|
||||
"/dhdeh/@1234",
|
||||
"?aj=r",
|
||||
"",
|
||||
intArrayOf(-1, 0, 7, -1, 15, 27, -1),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test16() =
|
||||
testUrlMarker(
|
||||
"bloop:@noooo.com/doop/@1234",
|
||||
"https",
|
||||
"bloop",
|
||||
"",
|
||||
"noooo.com",
|
||||
443,
|
||||
"/doop/@1234",
|
||||
"",
|
||||
"",
|
||||
intArrayOf(-1, 0, 7, -1, 16, -1, -1),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test17() =
|
||||
testUrlMarker(
|
||||
"bah.com/lala/@1234/@dfd@df?@dsf#ono",
|
||||
"https",
|
||||
"",
|
||||
"",
|
||||
"bah.com",
|
||||
443,
|
||||
"/lala/@1234/@dfd@df",
|
||||
"?@dsf",
|
||||
"#ono",
|
||||
intArrayOf(-1, -1, 0, -1, 7, 26, 31),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun test18() =
|
||||
testUrlMarker(
|
||||
"https://dewd:dood@www.google.com:20/?why=is&this=test#?@Sdsf",
|
||||
"https",
|
||||
"dewd",
|
||||
"dood",
|
||||
"www.google.com",
|
||||
20,
|
||||
"/",
|
||||
"?why=is&this=test",
|
||||
"#?@Sdsf",
|
||||
intArrayOf(0, 8, 18, 33, 35, 36, 53),
|
||||
)
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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.urldetector.detection
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertContentEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class CharUtilsTest {
|
||||
@Test
|
||||
fun testCharUtilsIsHex() {
|
||||
val arr = charArrayOf('a', 'A', '0', '9')
|
||||
for (a in arr) {
|
||||
assertTrue(CharUtils.isHex(a))
|
||||
}
|
||||
|
||||
val arr2 = charArrayOf('~', ';', 'Z', 'g')
|
||||
for (a in arr2) {
|
||||
assertFalse(CharUtils.isHex(a))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCharUtilsIsNumeric() {
|
||||
val arr = charArrayOf('0', '4', '6', '9')
|
||||
for (a in arr) {
|
||||
assertTrue(CharUtils.isNumeric(a))
|
||||
}
|
||||
|
||||
val arr2 = charArrayOf('a', '~', 'A', 0.toChar())
|
||||
for (a in arr2) {
|
||||
assertFalse(CharUtils.isNumeric(a))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCharUtilsIsAlpha() {
|
||||
val arr = charArrayOf('a', 'Z', 'f', 'X')
|
||||
for (a in arr) {
|
||||
assertTrue(CharUtils.isAlpha(a))
|
||||
}
|
||||
|
||||
val arr2 = charArrayOf('0', '9', '[', '~')
|
||||
for (a in arr2) {
|
||||
assertFalse(CharUtils.isAlpha(a))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCharUtilsIsAlphaNumeric() {
|
||||
val arr = charArrayOf('a', 'G', '3', '9')
|
||||
for (a in arr) {
|
||||
assertTrue(CharUtils.isAlphaNumeric(a))
|
||||
}
|
||||
|
||||
val arr2 = charArrayOf('~', '-', '_', '\n')
|
||||
for (a in arr2) {
|
||||
assertFalse(CharUtils.isAlphaNumeric(a))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCharUtilsIsUnreserved() {
|
||||
val arr = charArrayOf('-', '.', 'a', '9', 'Z', '_', 'f')
|
||||
for (a in arr) {
|
||||
assertTrue(CharUtils.isUnreserved(a))
|
||||
}
|
||||
|
||||
val arr2 = charArrayOf(' ', '!', '(', '\n')
|
||||
for (a in arr2) {
|
||||
assertFalse(CharUtils.isUnreserved(a))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSplitByDot() {
|
||||
val stringsToSplit =
|
||||
listOf(
|
||||
"192.168.1.1",
|
||||
"..",
|
||||
"192%2e168%2e1%2e1",
|
||||
"asdf",
|
||||
"192.39%2e1%2E1",
|
||||
"as\uFF61awe.a3r23.lkajsf0ijr....",
|
||||
"%2e%2easdf",
|
||||
"sdoijf%2e",
|
||||
"ksjdfh.asdfkj.we%2",
|
||||
"0xc0%2e0x00%2e0x02%2e0xeb",
|
||||
"",
|
||||
)
|
||||
|
||||
val regex = "[\\.\u3002\uFF0E\uFF61]|%2e|%2E".toRegex()
|
||||
|
||||
stringsToSplit.forEach { stringToSplit ->
|
||||
assertContentEquals(
|
||||
stringToSplit.split(regex),
|
||||
CharUtils.splitByDot(stringToSplit),
|
||||
"Splitting $stringToSplit",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.urldetector.detection
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class InputTextReaderTest {
|
||||
@Test
|
||||
fun testSimpleRead() {
|
||||
val reader = InputTextReader(CONTENT)
|
||||
for (i in 0..<CONTENT.length) {
|
||||
assertEquals(reader.read(), CONTENT[i])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEOF() {
|
||||
val reader = InputTextReader(CONTENT)
|
||||
for (i in 0..<CONTENT.length - 1) {
|
||||
reader.read()
|
||||
}
|
||||
|
||||
assertFalse(reader.eof())
|
||||
reader.read()
|
||||
assertTrue(reader.eof())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGoBack() {
|
||||
val reader = InputTextReader(CONTENT)
|
||||
assertEquals(reader.read(), CONTENT[0])
|
||||
reader.goBack()
|
||||
assertEquals(reader.read(), CONTENT[0])
|
||||
assertEquals(reader.read(), CONTENT[1])
|
||||
assertEquals(reader.read(), CONTENT[2])
|
||||
reader.goBack()
|
||||
reader.goBack()
|
||||
assertEquals(reader.read(), CONTENT[1])
|
||||
assertEquals(reader.read(), CONTENT[2])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSeek() {
|
||||
val reader = InputTextReader(CONTENT)
|
||||
reader.seek(4)
|
||||
assertEquals(reader.read(), CONTENT[4])
|
||||
|
||||
reader.seek(1)
|
||||
assertEquals(reader.read(), CONTENT[1])
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val CONTENT = "HELLO WORLD"
|
||||
}
|
||||
}
|
||||
+643
@@ -0,0 +1,643 @@
|
||||
/*
|
||||
* 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.urldetector.detection
|
||||
|
||||
import com.vitorpamplona.quartz.utils.urldetector.Url
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class UriDetectionTest {
|
||||
@Test
|
||||
fun testBasicString() {
|
||||
runTest("hello world")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBasicDetect() {
|
||||
runTest("this is a link: www.google.com", "www.google.com")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSimple() {
|
||||
runTest(
|
||||
"http://www.linkedin.com/vshlos",
|
||||
"http://www.linkedin.com/vshlos",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEmailAndNormalUrl() {
|
||||
runTest(
|
||||
"my email is vshlosbe@linkedin.com and my site is http://www.linkedin.com/vshlos",
|
||||
"vshlosbe@linkedin.com",
|
||||
"http://www.linkedin.com/vshlos",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTwoBasicUrls() {
|
||||
runTest(
|
||||
"the url google.com is a lot better then www.google.com.",
|
||||
"google.com",
|
||||
"www.google.com.",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLongUrl() {
|
||||
runTest(
|
||||
"google.com.google.com is kind of a valid url",
|
||||
"google.com.google.com",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInternationalUrls() {
|
||||
runTest(
|
||||
"this is an international domain: http://\u043F\u0440\u0438\u043c\u0435\u0440.\u0438\u0441\u043f\u044b" +
|
||||
"\u0442\u0430\u043d\u0438\u0435 so is this: \u4e94\u7926\u767c\u5c55.\u4e2d\u570b.",
|
||||
"http://\u043F\u0440\u0438\u043c\u0435\u0440.\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435",
|
||||
"\u4e94\u7926\u767c\u5c55.\u4e2d\u570b.",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDomainWithUsernameAndPassword() {
|
||||
runTest(
|
||||
"domain with username is http://username:password@www.google.com/site/1/2",
|
||||
"http://username:password@www.google.com/site/1/2",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFTPWithUsernameAndPassword() {
|
||||
runTest(
|
||||
"ftp with username is ftp://username:password@www.google.com",
|
||||
"ftp://username:password@www.google.com",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUncommonFormatUsernameAndPassword() {
|
||||
runTest(
|
||||
"weird url with username is username:password@www.google.com",
|
||||
"username:password@www.google.com",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEmailAndLinkWithUserPass() {
|
||||
runTest(
|
||||
"email and username is hello@test.google.com or hello@www.google.com hello:password@www.google.com",
|
||||
"hello@test.google.com",
|
||||
"hello@www.google.com",
|
||||
"hello:password@www.google.com",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWrongSpacingInSentence() {
|
||||
runTest(
|
||||
"I would not like to work at salesforce.com, it looks like a crap company.and not cool!",
|
||||
"salesforce.com",
|
||||
"company.and",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNumbersAreNotDetected() {
|
||||
// make sure pure numbers don't work, but domains with numbers do.
|
||||
runTest("Do numbers work? such as 3.1415 or 4.com", "4.com")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNewLinesAndTabsAreDelimiters() {
|
||||
runTest(
|
||||
"Do newlines and tabs break? google.com/hello/\nworld www.yahoo.com\t/stuff/ yahoo.com/\thello news.ycombinator.com\u0000/hello world",
|
||||
"google.com/hello/",
|
||||
"www.yahoo.com",
|
||||
"yahoo.com/",
|
||||
"news.ycombinator.com",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIpAddressFormat() {
|
||||
runTest(
|
||||
"How about IP addresses? fake: 1.1.1 1.1.1.1.1 0.0.0.256 255.255.255.256 real: 1.1.1.1 192.168.10.1 1.1.1.1.com 255.255.255.255",
|
||||
"1.1.1.1",
|
||||
"192.168.10.1",
|
||||
"1.1.1.1.com",
|
||||
"255.255.255.255",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNumericIpAddress() {
|
||||
runTest(
|
||||
"http://3232235521/helloworld",
|
||||
"http://3232235521/helloworld",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNumericIpAddressWithPort() {
|
||||
runTest(
|
||||
"http://3232235521:8080/helloworld",
|
||||
"http://3232235521:8080/helloworld",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDomainAndLabelSizeConstraints() {
|
||||
// Really long addresses testing rules about total length of domain name and number of labels in a domain and size of each label.
|
||||
runTest(
|
||||
(
|
||||
"This will work: 1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.ly " +
|
||||
"This will not work: 1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.ly " +
|
||||
"This should as well: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc.dddddddddddddddddddddddddddddddddddddddddddddddddddddd.bit.ly " +
|
||||
"But this wont: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc.dddddddddddddddddddddddddddddddddddddddddddddddddddddd.bit.ly.dbl.spamhaus.org"
|
||||
),
|
||||
"1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.ly",
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc.dddddddddddddddddddddddddddddddddddddddddddddddddddddd.bit.ly",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIncorrectParsingHtmlWithBadOptions() {
|
||||
runTest(
|
||||
"<a href=\"http://www.google.com/\">google.com</a>",
|
||||
"http://www.google.com/\">google.com</a>",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNonStandardDots() {
|
||||
runTest(
|
||||
"www\u3002google\u3002com username:password@www\uFF0Eyahoo\uFF0Ecom http://www\uFF61facebook\uFF61com http://192\u3002168\uFF0E0\uFF611/",
|
||||
"www\u3002google\u3002com",
|
||||
"username:password@www\uFF0Eyahoo\uFF0Ecom",
|
||||
"http://www\uFF61facebook\uFF61com",
|
||||
"http://192\u3002168\uFF0E0\uFF611/",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNonStandardDotsBacktracking() {
|
||||
runTest("\u9053 \u83dc\u3002\u3002\u3002\u3002")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBacktrackingStrangeFormats() {
|
||||
runTest(
|
||||
"http:http:http://www.google.com www.www:yahoo.com yahoo.com.br hello.hello..hello.com",
|
||||
"http://www.google.com",
|
||||
"www.www",
|
||||
"yahoo.com",
|
||||
"yahoo.com.br",
|
||||
"hello.hello.",
|
||||
"hello.com",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBacktrackingUsernamePassword() {
|
||||
runTest("check out my url:www.google.com", "www.google.com")
|
||||
runTest("check out my url:www.google.com ", "www.google.com")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBacktrackingEmptyDomainName() {
|
||||
runTest("check out my http:///hello")
|
||||
runTest("check out my http://./hello")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDoubleScheme() {
|
||||
runTest("http://http://")
|
||||
runTest("hello http://http://")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMultipleSchemes() {
|
||||
runTest("http://http://www.google.com", "http://www.google.com")
|
||||
runTest(
|
||||
"make sure it's right here http://http://www.google.com",
|
||||
"http://www.google.com",
|
||||
)
|
||||
runTest(
|
||||
"http://http://http://www.google.com",
|
||||
"http://www.google.com",
|
||||
)
|
||||
runTest(
|
||||
"make sure it's right here http://http://http://www.google.com",
|
||||
"http://www.google.com",
|
||||
)
|
||||
runTest(
|
||||
"http://ftp://https://www.google.com",
|
||||
"https://www.google.com",
|
||||
)
|
||||
runTest(
|
||||
"make sure its right here http://ftp://https://www.google.com",
|
||||
"https://www.google.com",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDottedHexIpAddress() {
|
||||
runTest(
|
||||
"http://0xc0.0x00.0xb2.0xEB",
|
||||
"http://0xc0.0x00.0xb2.0xEB",
|
||||
)
|
||||
runTest(
|
||||
"http://0xc0.0x0.0xb2.0xEB",
|
||||
"http://0xc0.0x0.0xb2.0xEB",
|
||||
)
|
||||
runTest(
|
||||
"http://0x000c0.0x00000.0xb2.0xEB",
|
||||
"http://0x000c0.0x00000.0xb2.0xEB",
|
||||
)
|
||||
runTest(
|
||||
"http://0xc0.0x00.0xb2.0xEB/bobo",
|
||||
"http://0xc0.0x00.0xb2.0xEB/bobo",
|
||||
)
|
||||
runTest(
|
||||
"ooh look i can find it in text http://0xc0.0x00.0xb2.0xEB/bobo like this",
|
||||
"http://0xc0.0x00.0xb2.0xEB/bobo",
|
||||
)
|
||||
runTest(
|
||||
"noscheme look 0xc0.0x00.0xb2.0xEB/bobo",
|
||||
"0xc0.0x00.0xb2.0xEB/bobo",
|
||||
)
|
||||
runTest(
|
||||
"no scheme 0xc0.0x00.0xb2.0xEB or path",
|
||||
"0xc0.0x00.0xb2.0xEB",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDottedOctalIpAddress() {
|
||||
runTest(
|
||||
"http://0301.0250.0002.0353",
|
||||
"http://0301.0250.0002.0353",
|
||||
)
|
||||
runTest(
|
||||
"http://0301.0250.0002.0353/bobo",
|
||||
"http://0301.0250.0002.0353/bobo",
|
||||
)
|
||||
runTest("http://192.168.017.015/", "http://192.168.017.015/")
|
||||
runTest(
|
||||
"ooh look i can find it in text http://0301.0250.0002.0353/bobo like this",
|
||||
"http://0301.0250.0002.0353/bobo",
|
||||
)
|
||||
runTest(
|
||||
"noscheme look 0301.0250.0002.0353/bobo",
|
||||
"0301.0250.0002.0353/bobo",
|
||||
)
|
||||
runTest(
|
||||
"no scheme 0301.0250.0002.0353 or path",
|
||||
"0301.0250.0002.0353",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHexIpAddress() {
|
||||
runTest("http://0xC00002EB/hello", "http://0xC00002EB/hello")
|
||||
runTest(
|
||||
"http://0xC00002EB.com/hello",
|
||||
"http://0xC00002EB.com/hello",
|
||||
)
|
||||
runTest(
|
||||
"still look it up as a normal url http://0xC00002EXsB.com/hello",
|
||||
"http://0xC00002EXsB.com/hello",
|
||||
)
|
||||
runTest(
|
||||
"ooh look i can find it in text http://0xC00002EB/bobo like this",
|
||||
"http://0xC00002EB/bobo",
|
||||
)
|
||||
runTest(
|
||||
"browsers dont support this without a scheme look 0xC00002EB/bobo",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOctalIpAddress() {
|
||||
runTest(
|
||||
"http://030000001353/bobobo",
|
||||
"http://030000001353/bobobo",
|
||||
)
|
||||
runTest(
|
||||
"ooh look i can find it in text http://030000001353/bobo like this",
|
||||
"http://030000001353/bobo",
|
||||
)
|
||||
runTest(
|
||||
"browsers dont support this without a scheme look 030000001353/bobo",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUrlWithEmptyPort() {
|
||||
runTest(
|
||||
"http://wtfismyip.com://foo.html",
|
||||
"http://wtfismyip.com://foo.html",
|
||||
)
|
||||
runTest(
|
||||
"make sure its right here http://wtfismyip.com://foo.html",
|
||||
"http://wtfismyip.com://foo.html",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUrlEncodedDot() {
|
||||
runTest("hello www%2ewtfismyip%2ecom", "www%2ewtfismyip%2ecom")
|
||||
runTest("hello wtfismyip%2ecom", "wtfismyip%2ecom")
|
||||
runTest("http://wtfismyip%2ecom", "http://wtfismyip%2ecom")
|
||||
runTest(
|
||||
"make sure its right here http://wtfismyip%2ecom",
|
||||
"http://wtfismyip%2ecom",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUrlEncodedBadPath() {
|
||||
runTest("%2ewtfismyip")
|
||||
runTest("wtfismyip%2e")
|
||||
runTest("wtfismyip%2ecom%2e", "wtfismyip%2ecom%2e")
|
||||
runTest("wtfismyip%2ecom.", "wtfismyip%2ecom.")
|
||||
runTest("%2ewtfismyip%2ecom", "wtfismyip%2ecom")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDetectUrlEncoded() {
|
||||
runTest(
|
||||
"%77%77%77%2e%67%75%6d%62%6c%61%72%2e%63%6e",
|
||||
"%77%77%77%2e%67%75%6d%62%6c%61%72%2e%63%6e",
|
||||
)
|
||||
runTest(
|
||||
" asdf %77%77%77%2e%67%75%6d%62%6c%61%72%2e%63%6e",
|
||||
"%77%77%77%2e%67%75%6d%62%6c%61%72%2e%63%6e",
|
||||
)
|
||||
runTest(
|
||||
"%77%77%77%2e%67%75%6d%62%6c%61%72%2e%63%6e%2e",
|
||||
"%77%77%77%2e%67%75%6d%62%6c%61%72%2e%63%6e%2e",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIncompleteIpAddresses() {
|
||||
runTest("hello 10...")
|
||||
runTest("hello 10...1")
|
||||
runTest("hello 10..1.")
|
||||
runTest("hello 10..1.1")
|
||||
runTest("hello 10.1..1")
|
||||
runTest("hello 10.1.1.")
|
||||
runTest("hello .192..")
|
||||
runTest("hello .192..1")
|
||||
runTest("hello .192.1.")
|
||||
runTest("hello .192.1.1")
|
||||
runTest("hello ..3.")
|
||||
runTest("hello ..3.1")
|
||||
runTest("hello ...1")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIPv4EncodedDot() {
|
||||
runTest("hello 192%2e168%2e1%2e1", "192%2e168%2e1%2e1")
|
||||
runTest(
|
||||
"hello 192.168%2e1%2e1/lalala",
|
||||
"192.168%2e1%2e1/lalala",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIPv4HexEncodedDot() {
|
||||
runTest(
|
||||
"hello 0xee%2e0xbb%2e0x1%2e0x1",
|
||||
"0xee%2e0xbb%2e0x1%2e0x1",
|
||||
)
|
||||
runTest(
|
||||
"hello 0xee%2e0xbb.0x1%2e0x1/lalala",
|
||||
"0xee%2e0xbb.0x1%2e0x1/lalala",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIpv6BadWithGoodUrls() {
|
||||
runTest("[:::] [::] [bacd::]", "[::]", "[bacd::]")
|
||||
runTest("[:0][::]", "[::]")
|
||||
runTest("[:0:][::afaf]", "[::afaf]")
|
||||
runTest(
|
||||
"::] [fe80:aaaa:aaaa:aaaa::]",
|
||||
"[fe80:aaaa:aaaa:aaaa::]",
|
||||
)
|
||||
runTest(
|
||||
"fe80:22:]3123:[adf] [fe80:aaaa:aaaa:aaaa::]",
|
||||
"[fe80:aaaa:aaaa:aaaa::]",
|
||||
)
|
||||
runTest("[][123[][ae][fae][de][:a][d]aef:E][f")
|
||||
runTest("[][][]2[d][]][]]]:d][[[:d[e][aee:]af:")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIpv6BadWithGoodUrlsEmbedded() {
|
||||
runTest(
|
||||
"[fe80:aaaa:aaaa:aaaa:[::]3dd0:7f8e:57b7:34d5f]",
|
||||
"[::]",
|
||||
)
|
||||
runTest("[b[::7f8e]:55]akjef[::]", "[::7f8e]:55", "[::]")
|
||||
runTest(
|
||||
"[bcad::kkkk:aaaa:3dd0[::7f8e]:57b7:34d5]akjef[::]",
|
||||
"[::7f8e]:57",
|
||||
"[::]",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIpv6BadWithGoodUrlsWeirder() {
|
||||
runTest("[:[::]", "[::]")
|
||||
runTest("[:] [feed::]", "[feed::]")
|
||||
runTest(":[::feee]:]", "[::feee]")
|
||||
runTest(":[::feee]:]]", "[::feee]")
|
||||
runTest("[[:[::feee]:]", "[::feee]")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIpv6ConsecutiveGoodUrls() {
|
||||
runTest("[::afaf][eaea::][::]", "[::afaf]", "[eaea::]", "[::]")
|
||||
runTest("[::afaf]www.google.com", "[::afaf]", "www.google.com")
|
||||
runTest("[lalala:we][::]", "[::]")
|
||||
runTest("[::fe][::]", "[::fe]", "[::]")
|
||||
runTest("[aaaa::][:0:][::afaf]", "[aaaa::]", "[::afaf]")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIpv6BacktrackingUsernamePassword() {
|
||||
runTest("check out my url:google.com", "google.com")
|
||||
runTest(
|
||||
"check out my url:[::BAD:DEAD:BEEF:2e80:0:0]",
|
||||
"[::BAD:DEAD:BEEF:2e80:0:0]",
|
||||
)
|
||||
runTest(
|
||||
"check out my url:[::BAD:DEAD:BEEF:2e80:0:0] ",
|
||||
"[::BAD:DEAD:BEEF:2e80:0:0]",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIpv6BacktrackingEmptyDomainName() {
|
||||
runTest("check out my http:///[::2e80:0:0]", "[::2e80:0:0]")
|
||||
runTest("check out my http://./[::2e80:0:0]", "[::2e80:0:0]")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIpv6DoubleSchemeWithDomain() {
|
||||
runTest("http://http://[::2e80:0:0]", "http://[::2e80:0:0]")
|
||||
runTest(
|
||||
"make sure its right here http://http://[::2e80:0:0]",
|
||||
"http://[::2e80:0:0]",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIpv6MultipleSchemes() {
|
||||
runTest(
|
||||
"http://http://http://[::2e80:0:0]",
|
||||
"http://[::2e80:0:0]",
|
||||
)
|
||||
runTest(
|
||||
"make sure its right here http://http://[::2e80:0:0]",
|
||||
"http://[::2e80:0:0]",
|
||||
)
|
||||
runTest(
|
||||
"http://ftp://https://[::2e80:0:0]",
|
||||
"https://[::2e80:0:0]",
|
||||
)
|
||||
runTest(
|
||||
"make sure its right here http://ftp://https://[::2e80:0:0]",
|
||||
"https://[::2e80:0:0]",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIpv6FtpWithUsernameAndPassword() {
|
||||
runTest(
|
||||
"ftp with username is ftp://username:password@[::2e80:0:0]",
|
||||
"ftp://username:password@[::2e80:0:0]",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIpv6NewLinesAndTabsAreDelimiters() {
|
||||
runTest(
|
||||
"Do newlines and tabs break? [::2e80:0:0]/hello/\nworld [::BEEF:ADD:BEEF]\t/stuff/ [AAbb:AAbb:AAbb::]/\thello [::2e80:0:0\u0000]/hello world",
|
||||
"[::2e80:0:0]/hello/",
|
||||
"[::BEEF:ADD:BEEF]",
|
||||
"[AAbb:AAbb:AAbb::]/",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIpv6WithPort() {
|
||||
runTest(
|
||||
"http://[AAbb:AAbb:AAbb::]:8080/helloworld",
|
||||
"http://[AAbb:AAbb:AAbb::]:8080/helloworld",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIpv6IncorrectParsingHtmlWithBadOptions() {
|
||||
runTest(
|
||||
"<a href=\"http://[::AAbb:]/\">google.com</a>",
|
||||
"http://[::AAbb:]/\">google.com</a>",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIpv6EmptyPort() {
|
||||
runTest(
|
||||
"http://[::AAbb:]://foo.html",
|
||||
"http://[::AAbb:]://foo.html",
|
||||
)
|
||||
runTest(
|
||||
"make sure its right here http://[::AAbb:]://foo.html",
|
||||
"http://[::AAbb:]://foo.html",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBacktrackInvalidUsernamePassword() {
|
||||
runTest("http://hello:asdf.com", "asdf.com")
|
||||
}
|
||||
|
||||
/*
|
||||
* https://github.com/linkedin/URL-Detector/issues/12
|
||||
*/
|
||||
@Test
|
||||
fun testIssue12() {
|
||||
runTest(
|
||||
"http://user:pass@host.com host.com",
|
||||
"http://user:pass@host.com",
|
||||
"host.com",
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
* https://github.com/linkedin/URL-Detector/issues/15
|
||||
*/
|
||||
@Test
|
||||
fun testIssue15() {
|
||||
runTest(
|
||||
".............:::::::::::;;;;;;;;;;;;;;;::...............................................:::::::::::::::::::::::::::::....................",
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
* https://github.com/linkedin/URL-Detector/issues/16
|
||||
*/
|
||||
@Test
|
||||
fun testIssue16() {
|
||||
runTest("://VIVE MARINE LE PEN//:@.")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testColonWithoutSlashesFail() {
|
||||
val parser = UrlDetector("ftp:example.com")
|
||||
val found: List<Url> = parser.detect()
|
||||
for (url in found) {
|
||||
assertEquals(url.scheme, "https")
|
||||
// Should be detected as a username now and set to default http://
|
||||
assertEquals(url.host, "example.com")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIssueUnderscore() {
|
||||
runTest("Neomobius_at_mstdn.jp@mostr.pub", "Neomobius_at_mstdn.jp@mostr.pub")
|
||||
}
|
||||
|
||||
private fun runTest(
|
||||
text: String,
|
||||
vararg expected: String?,
|
||||
) = assertEquals(
|
||||
expected.toList(),
|
||||
UrlDetector(text).detect().map { it.originalUrl },
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user