[ruby-core:86189] [Ruby trunk Bug#11989] Dedenting interpolating heredoc can interpret escapes incorrectly

From: usa@...
Date: 2018-03-18 15:29:42 UTC
List: ruby-core #86189
Issue #11989 has been updated by usa (Usaku NAKAMURA).

Backport changed from 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: DONTNEED, 2.3: REQUIRED to 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: DONTNEED, 2.3: DONE

ruby_2_3 r62826 merged revision(s) 53573.

----------------------------------------
Bug #11989: Dedenting interpolating heredoc can interpret escapes incorrectly
https://bugs.ruby-lang.org/issues/11989#change-71076

* Author: whitequark (whitequark *)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
* Backport: 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: DONTNEED, 2.3: DONE
----------------------------------------
It is clear that the dedenting <<~HEREDOC feature was intended to only consider actual whitespace in the source file as indentation, not any escaped whitespace. E.g.:

~~~ruby
p <<~"E"
  \ x
   y
E
~~~

It prints `" x\n y\n"`. So `"\ "` does not count as whitespace. There is even an MRI test for this.

However, this case is handled differently:

~~~ruby
p <<~"E"
  x\n   y
E
~~~

It prints `"x\n y\n"`. So `"\n"` is counted as whitespace, like an actual newline would be. I think it should print `"x\n   y\n"`.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next