[ruby-core:112888] [Ruby master Bug#19485] Unexpected behavior in squiggly heredocs
From:
"nobu (Nobuyoshi Nakada) via ruby-core" <ruby-core@...>
Date:
2023-03-15 05:16:12 UTC
List:
ruby-core #112888
Issue #19485 has been updated by nobu (Nobuyoshi Nakada).
Status changed from Open to Assigned
Assignee set to core
Backport changed from 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN to 2.7: UNKNOWN, 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED
My draft is:
> Note that the "indentation" is counted like as each horizontal tabs are
> expanded to spaces up to the next tab stop column (per 8 columns), and each
> indentation to be removed is the longest tabs and spaces sequence where the
> next column does not exceed the least-indentation.
Does this make sense?
----------------------------------------
Bug #19485: Unexpected behavior in squiggly heredocs
https://bugs.ruby-lang.org/issues/19485#change-102404
* Author: jemmai (Jemma Issroff)
* Status: Assigned
* Priority: Normal
* Assignee: core
* ruby -v: 3.2.1
* Backport: 2.7: UNKNOWN, 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED
----------------------------------------
Based on [the squiggly heredoc documentation](https://ruby-doc.org/3.2.1/syntax/literals_rdoc.html), I found the following to be unexpected behavior. Explicitly, the documentation specifies, "The indentation of the least-indented line will be removed from each line of the content."
After running:
```ruby
File.write("test.rb", "p <<~EOF\n\ta\n b\nEOF\n")
```
and then `ruby test.rb`, I get the following output:
```
"\ta\nb\n"
```
The least-indented line above is ` b`, however, no leading whitespace is removed from the line containing `\ta`.
For another example:
```ruby
File.write("test.rb", "p <<~EOF\n\tA\n \tB\nEOF\n")
```
`ruby test.rb` gives:
```
"A\nB\n"
```
In this case, the `\t` was removed from the line containing `A`, but more whitespace than that (` \t`) was removed from the line containing `B`.
After seeing the first example, I assumed that the documentation was out of date, and that I should fix it to read that `\t` would never be converted into space characters in order to remove leading whitespace. But after the second example, it seems like this is a bug in removing leading whitespace.
Can someone please explain what the rules should be on squiggly heredocs? I can implement a fix to adhere to the rules, or can update the documentation, I am just unsure of what the rules should be because the above two examples reflect unexpected behavior in two distinct ways.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/