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

Named captures not supported in StringScanner on Ruby < 2.1 #557

Closed
tomeon opened this issue Dec 3, 2018 · 4 comments
Closed

Named captures not supported in StringScanner on Ruby < 2.1 #557

tomeon opened this issue Dec 3, 2018 · 4 comments
Assignees
Labels

Comments

@tomeon
Copy link

@tomeon tomeon commented Dec 3, 2018

Support for named captures in StringScanner was introduced in Ruby 2.1 on 2013-05-21; see the changelog entry.

There are several locations in which Kramdown::Utils::StringScanner#[] is invoked using a non-integer argument -- for example, line 48 of kramdown/parser/kramdown/header.rb. On Ruby 2.0.0, this can lead to errors like:

TypeError: no implicit conversion of String into Integer
/rbexec/vendor/bundle/ruby/2.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown/header.rb:48:in `[]'
/rbexec/vendor/bundle/ruby/2.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown/header.rb:48:in `parse_header_contents'
/rbexec/vendor/bundle/ruby/2.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown/header.rb:34:in `parse_atx_header'
/rbexec/vendor/bundle/ruby/2.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown.rb:148:in `block (2 levels) in parse_blocks'
/rbexec/vendor/bundle/ruby/2.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown.rb:146:in `each'
/rbexec/vendor/bundle/ruby/2.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown.rb:146:in `any?'
/rbexec/vendor/bundle/ruby/2.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown.rb:146:in `block in parse_blocks'
/rbexec/vendor/bundle/ruby/2.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown.rb:144:in `catch'
/rbexec/vendor/bundle/ruby/2.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown.rb:144:in `parse_blocks'
/rbexec/vendor/bundle/ruby/2.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown.rb:89:in `parse'
/rbexec/vendor/bundle/ruby/2.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/base.rb:69:in `parse'
/rbexec/vendor/bundle/ruby/2.0.0/gems/kramdown-1.17.0/lib/kramdown/document.rb:104:in `initialize'
/rbexec/vendor/bundle/ruby/2.0.0/gems/kramdown-man-0.1.6/lib/kramdown/man/task.rb:62:in `new'
/rbexec/vendor/bundle/ruby/2.0.0/gems/kramdown-man-0.1.6/lib/kramdown/man/task.rb:62:in `render'
/rbexec/vendor/bundle/ruby/2.0.0/gems/kramdown-man-0.1.6/lib/kramdown/man/task.rb:47:in `block (2 levels) in define'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/gems/bundler-1.16.3/lib/bundler/cli/exec.rb:74:in `load'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/gems/bundler-1.16.3/lib/bundler/cli/exec.rb:74:in `kernel_load'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/gems/bundler-1.16.3/lib/bundler/cli/exec.rb:28:in `run'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/gems/bundler-1.16.3/lib/bundler/cli.rb:424:in `exec'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/gems/bundler-1.16.3/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/gems/bundler-1.16.3/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/gems/bundler-1.16.3/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/gems/bundler-1.16.3/lib/bundler/cli.rb:27:in `dispatch'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/gems/bundler-1.16.3/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/gems/bundler-1.16.3/lib/bundler/cli.rb:18:in `start'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/gems/bundler-1.16.3/exe/bundle:30:in `block in <top (required)>'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/gems/bundler-1.16.3/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/gems/bundler-1.16.3/exe/bundle:22:in `<top (required)>'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/bin/bundle:23:in `load'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/bin/bundle:23:in `<main>'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/bin/ruby_executable_hooks:24:in `eval'
/home/travis/.rvm/gems/ruby-2.0.0-p648@global/bin/ruby_executable_hooks:24:in `<main>'

I believe that the simplest solution would be to deprecate support for Ruby < 2.1 via setting s.required_ruby_version = '>= 2.1' in the Rakefile, and I'd be happy to submit a PR introducing this change. I would also be happy to investigate a 2.0-compatible solution if dropping support for Ruby < 2.1 is not acceptable at this time.

@UltimateGeek
Copy link

@UltimateGeek UltimateGeek commented Dec 7, 2018

I think this started happening in 1.17.0 of kramdown. When I use kramdown 1.16.2 on ruby2.0, I don't see this problem. I agree with @tomeon that the gemspec needs to be updated to indicate a minimum requirement on ruby 2.1.

@gettalong gettalong self-assigned this Dec 12, 2018
@gettalong gettalong added the bug label Dec 12, 2018
@gettalong
Copy link
Owner

@gettalong gettalong commented Dec 12, 2018

Thanks for the report! I think deprecating support for deprecated Ruby versions will be the way to go.

@gettalong
Copy link
Owner

@gettalong gettalong commented Jan 9, 2019

The next version of kramdown will require at least Ruby 2.3 since that is the lowest Ruby version still supported.

@gettalong gettalong closed this Jan 9, 2019
@tomeon
Copy link
Author

@tomeon tomeon commented Jan 9, 2019

TYVM, @gettalong!

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

Successfully merging a pull request may close this issue.

None yet
3 participants