User Pudong is trying to create a hyperlink to a file on a server share using a UNC path in Discourse. Initially, the link appears but doesn’t work when clicked. David suggests adding “file” to the “allowed href schemes” site setting, which resolves the issue for Pudong.
However, other users, including Pierre_GRAND and user2, report issues with the file scheme, with Discourse replacing it with https. Jomaxro confirms that adding custom schemes like ftp works, but not file. Codinghorror and jomaxro investigate further, but the issue persists.
Davidd discovers that using HTML syntax <a href="file://myfile">link</a> works, but the Markdown syntax does not. He also finds that the sanitizer treats links with three slashes (file:///) as invalid. User2 reports that this issue applies to Windows paths as well.
Ultimately, david concludes that the issue is due to a browser security restriction in Chrome 76 (July 2019), which blocks file:// links, and there’s nothing Discourse can do to resolve this.
Hello,
I have added file to “allowed href schemes” but when I create a hyperlink using a file:// url, Discourse will post it with https instead of file.
Then when changing the https back to “file” it’s still opening a https link when clicking on it.
Is the “file” scheme supported in Discourse(I’m in v2.2.0.beta2 +5)?
br
Can confirm that we did not regress completely, adding ftp or steam works. I cannot get file to work, however, though that could just mean I’m doing something wrong. Never used the file href scheme before.
No clue. As mentioned, I’ve never seen the file href before. I used 3 for my screenshot as that’s what I saw over on SO: https://stackoverflow.com/questions/12837024/href-file-doesnt-work. In any case, I tried 1 (just in case), 2 (normal), 3 (SO answer), 4, & 5 (example in OP) slashes, none worked.
Hi, I’m trying to use local links to PDF documents on local shared network device. I run Discourse locally as a documentation tool. I have tried to add “file” in the href settings, but cannot get a working local link. Is there any way around this? Is this broken or am I doing it wrong?
It’s weird… <a href="file://myfile">link</a> works, but [link](file://myfile) does not. But both options work for other custom schemes as @jomaxro said
Maybe something in the commonmark link internals is stripping out file:// specifically. A quick search doesn’t reveal anything obvious in the discourse codebase.
@user2 the workaround for now is to use the HTML syntax for your link
<a href="file://myfile">link</a>
Edit: even with that, we still have an issue with file:// protocols. It is very common for file paths to start with a / (signifying the root of the filesystem), so the link looks like file:///myfile. Our sanitizer doesn’t like the three slashes at the beginning, and treats the link as invalid.
Opened a file in browser and I see file:///K:/file...., same on windows. But <a href="file://myfile">link</a> does not work either. Maybe it works on *nix based system but not on windows paths?