Skip to content

Commit

Permalink
fix : URI_DETECTOR regex, added custom detector localhost and mailto
Browse files Browse the repository at this point in the history
  • Loading branch information
David committed Oct 18, 2023
1 parent 2629949 commit c7db93c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ class ReferenceProviderImpl(private val basePath: Path, documents: Map<Path, Pag
ReferenceProvider {

companion object {
private const val URI_DETECTOR = "^(https?|ftp)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"
private const val URI_DETECTOR = "^(https?|ftp)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;'()]*[-a-zA-Z0-9+&@#/%=~_|]"
private const val MAILTO_DETECTOR = "mailto:"
private const val LOCALHOST_DETECTOR = "localhost:"

private val logger = KotlinLogging.logger {}
}
fun isValid(url: String): Boolean {
Expand All @@ -60,6 +62,7 @@ class ReferenceProviderImpl(private val basePath: Path, documents: Map<Path, Pag
override fun resolveReference(source: Path, refTo: String): Reference? {

if (refTo.startsWith(MAILTO_DETECTOR)) return null
if (refTo.startsWith(LOCALHOST_DETECTOR)) return null
if (isValid(refTo)) return null
if (refTo.startsWith("#")) return Anchor(refTo.substring(1))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,27 @@ internal class ReferenceProviderImplTest {

assertThat(result).isNull()
}


@Test
internal fun `French url resolution`() {
val result = providerImpl.resolveReference(Path("docs/one.md"), "http://github.com/handle'case")

assertThat(result).isNull()
}

@Test
internal fun `Parenthesis url resolution`() {
val result = providerImpl.resolveReference(Path("docs/one.md"), "http://github.com/handle()case")

assertThat(result).isNull()
}

@Test
internal fun `localhost url resolution`() {
val result = providerImpl.resolveReference(Path("docs/one.md"), "localhost:9000")

assertThat(result).isNull()
}

}

0 comments on commit c7db93c

Please sign in to comment.