External links with # gets broken.
Somya545 opened this issue · comments
Hi, I am trying to preview a link with # the link doesn't open and seems to be broken.
https://htmlpreview.github.io/?https://github.com/userID/blob/master/vignettes/Testing.html#
Attaching an image below for reference.
But, once I remove the "#" from the same link and try to access, the link opens.
I ran into this bug as well, and it's pretty surprising and frustrating.
When viewing my page:
https://htmlpreview.github.io/?https://github.com/ZimbiX/brendan-weibrecht-resume/blob/master/build/brendan-weibrecht-resume.html
where I had a link to this URL:
https://github.com/docker/for-linux/issues/1015#issuecomment-841915668
The bug replaces it with:
https://htmlpreview.github.io/?https://github.com/ZimbiX/brendan-weibrecht-resume/blob/master/build/brendan-weibrecht-resume.html#issuecomment-841915668
The problem code is here:
htmlpreview.github.com/htmlpreview.js
Lines 24 to 25 in 787b673
I don't really know what the usecase of this URL replacement is. The condition seems to assume the link is to an anchor within the current page; but in my case, it's on an external URL.
I was going to attempt a fix myself, but without a test suite, I don't know what functionality I'd be breaking 😕
For now, I've had to work around the bug, using a URL shortener to preserve the anchor in the link: ZimbiX/brendan-weibrecht-resume@4616a44
@ZimbiX That line 25 is for cases when the anchor is targeting a section on the same page, i.e. <a href="#section">
- we don't want to rewrite such URLs using htmlpreview.github.io.
However, there should be an added check: if there is an anchor and the URL before # is not the same as the original, then add the rewrite.
@niutech Thanks for your response. I think I could have expessed myself clearer. I understood that links like <a href="#section">
are sensibly left alone (href.indexOf('#') > 0
is false). But what kind of link is supposed to be matched and adjusted by line 25? Just links where the URL, minus the anchor, is the same as the current page? But can this app actually even display such a page where that kind of link would've worked in the original page? Like, we're fetching a HTML file from GitHub and it has no URL that can actually display the page, right? Hence the reason for creating this app?
I can't yet see a valid usecase for this particular replacement code; if there isn't one, we should probably remove it.