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

StringScanner#scan does not accept a String argument as a pattern #2423

Closed
postmodern opened this issue Aug 18, 2021 · 2 comments
Closed

StringScanner#scan does not accept a String argument as a pattern #2423

postmodern opened this issue Aug 18, 2021 · 2 comments
Assignees
Milestone

Comments

@postmodern
Copy link

In strscan 1.0.2 Strings can be given as a literal pattern to scan:

require 'strscan'
scanner = StringScanner.new("foo bar baz")
scanner.scan("foo")
# => "foo"
scanner.scan(/\s+/)
# => " "

truffleruby-21.2.0.1 claims to ship with strscan-1.0.3, however it does not accept a String as a pattern argument.

$ truffleruby -v
truffleruby 21.2.0.1, like ruby 2.7.3, GraalVM CE Native [x86_64-linux]
$ gem list strscan

*** LOCAL GEMS ***

strscan (default: 1.0.3)
scanner.scan("foo")
Traceback (most recent call last):
	from /opt/rubies/truffleruby-21.2.0.1/bin/irb:42:in `<main>'
	from <internal:core> core/kernel.rb:400:in `load'
	from <internal:core> core/kernel.rb:400:in `load'
	from /opt/rubies/truffleruby-21.2.0.1/lib/gems/gems/irb-1.3.3/exe/irb:11:in `<top (required)>'
	from <internal:core> core/throw_catch.rb:36:in `catch'
	from <internal:core> core/throw_catch.rb:36:in `catch'
	from <internal:core> core/kernel.rb:437:in `loop'
	from <internal:core> core/kernel.rb:325:in `eval'
	from (irb):3:in `<top (required)>'
	from /opt/rubies/truffleruby-21.2.0.1/lib/truffle/strscan.rb:243:in `scan'
/opt/rubies/truffleruby-21.2.0.1/lib/truffle/strscan.rb:313:in `scan_internal': bad pattern argument: "foo" (TypeError)
@eregon
Copy link
Member

eregon commented Aug 19, 2021

Thanks for the report.

TruffleRuby has its own implementation of strscan in Ruby code for efficiency.
It needs to declare the default gem too, so it uses the same gemspec.

As part of the import from MRI, we already have the strscan tests in https://github.com/oracle/truffleruby/blob/master/test/mri/tests/strscan/test_stringscanner.rb.
So we just need to implement this new case and untag the corresponding MRI test.
The feature was added in ruby/strscan#4, it's only for headonly so we can use String#start_with? to implement it.

@aardvark179
Copy link
Contributor

aardvark179 commented Jan 11, 2022

This was fixed in commit 15bb22a

@eregon eregon added this to the 21.3.0 milestone Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants