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

"index out of string" error in Strings.wrap #16

Open
jscheid opened this issue Nov 16, 2021 · 1 comment
Open

"index out of string" error in Strings.wrap #16

jscheid opened this issue Nov 16, 2021 · 1 comment

Comments

@jscheid
Copy link

jscheid commented Nov 16, 2021

Describe the problem

Strings.wrap throws an IndexError.

Steps to reproduce the problem

Strings.wrap(
  "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz   \e[1m\e[35m zzzzzzz\e[0m  \e[1m\e[35mzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
  62
)

Actual behaviour

         [snip]
	 8: from /usr/local/bundle/gems/strings-0.2.1/lib/strings.rb:109:in `wrap'
	 7: from /usr/local/bundle/gems/strings-0.2.1/lib/strings/wrap.rb:29:in `wrap'
	 6: from /usr/local/bundle/gems/strings-0.2.1/lib/strings/wrap.rb:29:in `map'
	 5: from /usr/local/bundle/gems/strings-0.2.1/lib/strings/wrap.rb:30:in `block in wrap'
	 4: from /usr/local/bundle/gems/strings-0.2.1/lib/strings/wrap.rb:111:in `format_line'
	 3: from /usr/local/bundle/gems/strings-0.2.1/lib/strings/wrap.rb:142:in `insert_ansi'
	 2: from /usr/local/bundle/gems/strings-0.2.1/lib/strings/wrap.rb:142:in `reverse_each'
	 1: from /usr/local/bundle/gems/strings-0.2.1/lib/strings/wrap.rb:158:in `block in insert_ansi'
/usr/local/bundle/gems/strings-0.2.1/lib/strings/wrap.rb:158:in `insert': index 56 out of string (IndexError)

Expected behaviour

What did you expect to happen?

Describe your environment

  • OS version: Debian 10.9
  • Ruby version: ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
  • Strings version: 0.2.1
@jscheid jscheid changed the title "index out of string" error in String.wrap "index out of string" error in Strings.wrap Nov 16, 2021
@jscheid
Copy link
Author

jscheid commented Nov 16, 2021

Looking at the code and at the skipped test cases, it seems that a lot of the complexity comes from trying to re-apply the "stack" of ANSI codes on following lines.

Considering that ANSI codes normally survive to the next line, is this really necessary in the first place? What prompted this feature?

Screen Shot 2021-11-17 at 08 44 49

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

No branches or pull requests

1 participant