-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix : URI detector/template loading from windows fs #110
fix : URI detector/template loading from windows fs #110
Conversation
This reverts commit 9e0bf7e.
1bcbbc3
to
2629949
Compare
@@ -27,9 +28,10 @@ class AsciidocParser( | |||
} | |||
|
|||
private val templatesLocation: Path by lazy { | |||
val templateResources = AsciidocParser::class.java.getResource(TEMPLATES_LOCATION)!!.toURI() | |||
val templateResources = AsciidocParser::class.java.classLoader.getResource(TEMPLATES_LOCATION)!!.toURI() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the reason for this change?
@@ -70,6 +71,7 @@ class PageContentTest { | |||
|
|||
@Test | |||
internal fun `Invalid result for unbalanced xml`() { | |||
Locale.setDefault(Locale.ENGLISH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a bad idea - especially taking into account that you do it without any try/finally/extension way.
It's better to use something like this https://wesome.org/junit-5-pioneer-defaultlocale or create adhoc extension in tests to do something similar
private val logger = KotlinLogging.logger {} | ||
} | ||
fun isValid(url: String): Boolean { | ||
val pattern = Pattern.compile(URI_DETECTOR, Pattern.CASE_INSENSITIVE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use regex as a field instead to avoid compiling regex string every time. Original code worked better, so please rollback to original approach.
} | ||
|
||
private val normalizedDocs = | ||
documents.map { (path, header) -> path.relativeTo(basePath).normalize() to header }.toMap() | ||
|
||
override fun resolveReference(source: Path, refTo: String): Reference? { | ||
if (URI_DETECTOR.matches(refTo)) return null | ||
|
||
if (refTo.startsWith(MAILTO_DETECTOR)) return null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't get what's the reason of doing multiple matches - how about simply slightly adjusting original regex to catch url scheme and checking that it's http, https, ftp or mailto?
|
||
if (refTo.startsWith(MAILTO_DETECTOR)) return null | ||
if (refTo.startsWith(LOCALHOST_DETECTOR)) return null | ||
if (isValid(refTo)) return null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
method name is confusing - what does "valid" mean here? better to rename with isExternalUrl
or something like this
val document = normalizedDocs[targetPath]?.title ?: return null | ||
return Xref(document, anchor) | ||
} catch (ex: InvalidPathException) { | ||
logger.error { "Failed to resolve : $refTo from $source" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a bad pattern - log error and rethrow exception - because you'd get one more logging in another place. Either do not log or throw another exception with chained root cause.
|
||
|
||
@Test | ||
internal fun `Http resolution`() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR title says that there is some fix for windows. What actually is failing here on windows?
Fixed in #116. Differences:
|
No description provided.