Skip to content
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

Link detection faulty #65

Open
lenzls opened this issue Dec 22, 2019 · 0 comments
Open

Link detection faulty #65

lenzls opened this issue Dec 22, 2019 · 0 comments

Comments

@lenzls
Copy link

lenzls commented Dec 22, 2019

Hello,

while trying to hook into hyperlink processing (to make relative links work), I realized that hyperlink parsing in general seems to be broken.

problem

Suppose we have a markdown like

 1. [link!](https://www.example.com)
 2. [link!](example.com)
 3. [link!](56366)

All three should be valid and interpreted as links. But rxmarkdown only interprets (1) as a link. The others are ignored and rendered as [link!](example.com) and [link!](56366) in the output.

presumed cause

com.yydcdut.markdown.syntax.text.HyperLinkSyntax#contains seems to be broken.
It return in all three cases false. While it should actually return true in all three cases.

As a result, you only check in line 60 the AUTO_LINK_PATTERN regex to see if you can do auto linking in this line. And for case (1) this actually works. That's why line (1) is interpreted correctly as a link but the other two not.

The problem lies in line 106 and following.
Here

                    if (TextHelper.getChar(array, ++i) == 0 || TextHelper.getChar(findArray, ++findPosition) == 0) {
                        return false;
                    }
                    if (TextHelper.getChar(array, ++i) != TextHelper.getChar(findArray, ++findPosition)) {
                        findPosition--;
                    } else {
                        findPosition++;
                    }

you increment i and findPosition in the method calls which results in incorrect behaviour. I guess replacing eg. ++i with i+1 (and the same for findPosition would solve the problem.

On the other hand, I'm not entirely sure, why you need this method at all. Isn't matching with the PATTERN regex from the same file enough to detect whether the string contains a markdown link? It looks like the method tries to do the same as matching the regex programmatically (but does it faulty).

regards,

Simon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant