Crash when using shebang inside code block
VeteraNovis opened this issue · 4 comments
VeteraNovis commented
Description of Error
If a code block contains a shebang (#!) at the start of the line (or preceeded by whitespace characters), then mdless will crash with the following error:
Traceback (most recent call last):
9: from /snap/mdless/274/bin/mdless:23:in `<main>'
8: from /snap/mdless/274/bin/mdless:23:in `load'
7: from /snap/mdless/274/gems/mdless-1.0.21/bin/mdless:17:in `<top (required)>'
6: from /snap/mdless/274/gems/mdless-1.0.21/bin/mdless:17:in `new'
5: from /snap/mdless/274/gems/mdless-1.0.21/lib/mdless/converter.rb:127:in `initialize'
4: from /snap/mdless/274/gems/mdless-1.0.21/lib/mdless/converter.rb:127:in `each'
3: from /snap/mdless/274/gems/mdless-1.0.21/lib/mdless/converter.rb:140:in `block in initialize'
2: from /snap/mdless/274/gems/mdless-1.0.21/lib/mdless/converter.rb:586:in `convert_markdown'
1: from /snap/mdless/274/gems/mdless-1.0.21/lib/mdless/converter.rb:586:in `gsub!'
/snap/mdless/274/gems/mdless-1.0.21/lib/mdless/converter.rb:600:in `block in convert_markdown': undefined method `[]' for nil:NilClass (NoMethodError)
Sample file
Attached is an example file which crashes upon attempting to be read
mdless-crash.md
Version
mdless 1.0.21
system
Ubuntu 21.04
ttscoff commented
Fixed. It's only happening because the shebang is empty. The regex
wasn't expecting a shebang with no content.
…-Brett
On 19 Oct 2021, at 3:20, VeteraNovis wrote:
## Description of Error
If a code block contains a shebang (#!) at the start of the line (or
preceeded by whitespace characters), then mdless will crash with the
following error:
```
Traceback (most recent call last):
9: from /snap/mdless/274/bin/mdless:23:in `<main>'
8: from /snap/mdless/274/bin/mdless:23:in `load'
7: from /snap/mdless/274/gems/mdless-1.0.21/bin/mdless:17:in `<top
(required)>'
6: from /snap/mdless/274/gems/mdless-1.0.21/bin/mdless:17:in `new'
5: from
/snap/mdless/274/gems/mdless-1.0.21/lib/mdless/converter.rb:127:in
`initialize'
4: from
/snap/mdless/274/gems/mdless-1.0.21/lib/mdless/converter.rb:127:in
`each'
3: from
/snap/mdless/274/gems/mdless-1.0.21/lib/mdless/converter.rb:140:in
`block in initialize'
2: from
/snap/mdless/274/gems/mdless-1.0.21/lib/mdless/converter.rb:586:in
`convert_markdown'
1: from
/snap/mdless/274/gems/mdless-1.0.21/lib/mdless/converter.rb:586:in
`gsub!'
/snap/mdless/274/gems/mdless-1.0.21/lib/mdless/converter.rb:600:in
`block in convert_markdown': undefined method `[]' for nil:NilClass
(NoMethodError)
```
## Sample file
Attached is an example file which crashes upon attempting to be read
[mdless-crash.md](https://github.com/ttscoff/mdless/files/7371498/mdless-crash.md)
## Version
```
mdless 1.0.21
```
## system
```
Ubuntu 21.04
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
#75
VeteraNovis commented
Ah it was happening even with content. I only stripped it down to the shebang to keep it as simple as possible when testing the crash.
I first noticed it with code block like the following
#!com.test.sample
ttscoff commented
A hash bang has a path in it, e.g. #!/bin/bash. The regex was expecting to split on the slashes, so it was breaking if there weren’t any. Now it just doesn’t try to parse it if there aren’t any slashes.
- Brett
…On Oct 19, 2021, 7:14 PM -0500, VeteraNovis ***@***.***>, wrote:
Ah it was happening even with content. I only stripped it down to the shebang to keep it as simple as possible when testing the crash.
I first noticed it with code block like the following
#!com.test.sample
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
VeteraNovis commented
Thanks for the work mate!