Skip to content

Commit

Permalink
Skip empty URLs when inlining images
Browse files Browse the repository at this point in the history
Markdown links like `[foo]()`, while basically invalid, do not usually
cause too much trouble, or at least shouldn't cause problems in
unrelated code. It so happens that if a document happens to have such
a link, `markdown-toggle-inline-images` will crash with:

    insert-file-contents-literally: not a regular file: /tmp/default-directory-path/

This patch fixes the problem by checking if the `file` path extracted
from the regex is empty before proceeding with treating it like an image.
  • Loading branch information
anarcat authored and jrblevin committed May 26, 2018
1 parent c0fc524 commit baf23cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
- Fix precedence of inline code over inline links.
- Improve error reporting for `markdown` and `markdown-open`.
([GH-291][])
- Fix M-RET binding for terminals ([GH-317][])
- Fix M-RET binding for terminals. ([GH-317][])
- Do not fail displaying inline images on empty links. ([GH-320][])

[gh-171]: https://github.com/jrblevin/markdown-mode/issues/171
[gh-216]: https://github.com/jrblevin/markdown-mode/issues/216
Expand Down Expand Up @@ -143,6 +144,7 @@
[gh-296]: https://github.com/jrblevin/markdown-mode/issues/296
[gh-303]: https://github.com/jrblevin/markdown-mode/pull/303
[gh-317]: https://github.com/jrblevin/markdown-mode/pull/317
[gh-320]: https://github.com/jrblevin/markdown-mode/pull/320

# Markdown Mode 2.3

Expand Down
3 changes: 2 additions & 1 deletion markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -8376,7 +8376,8 @@ or \\[markdown-toggle-inline-images]."
(let ((start (match-beginning 0))
(end (match-end 0))
(file (match-string-no-properties 6)))
(when (file-exists-p file)
(when (and (not (zerop (length file)))
(file-exists-p file))
(let* ((abspath (if (file-name-absolute-p file)
file
(concat default-directory file)))
Expand Down

0 comments on commit baf23cb

Please sign in to comment.