[#118180] [Ruby master Bug#20525] Percent string literal with indentation support — "bradgessler (Brad Gessler) via ruby-core" <ruby-core@...>

Issue #20525 has been reported by bradgessler (Brad Gessler).

8 messages 2024/06/04

[#118243] [Ruby master Feature#20564] Switch default parser to Prism — "kddnewton (Kevin Newton) via ruby-core" <ruby-core@...>

Issue #20564 has been reported by kddnewton (Kevin Newton).

11 messages 2024/06/07

[#118269] [Ruby master Bug#20570] Nokey behavior changed since 3.3. — "ksss (Yuki Kurihara) via ruby-core" <ruby-core@...>

Issue #20570 has been reported by ksss (Yuki Kurihara).

8 messages 2024/06/10

[#118279] [Ruby master Bug#20573] Warning.warn shouldn't be called for disabled warnings — "tenderlovemaking (Aaron Patterson) via ruby-core" <ruby-core@...>

Issue #20573 has been reported by tenderlovemaking (Aaron Patterson).

10 messages 2024/06/10

[#118281] [Ruby master Misc#20574] DevMeeting-2024-07-11 — "mame (Yusuke Endoh) via ruby-core" <ruby-core@...>

Issue #20574 has been reported by mame (Yusuke Endoh).

12 messages 2024/06/11

[#118346] [Ruby master Bug#20586] Some filesystem calls in dir.c are missing error handling and can return incorrect results if interrupted — "ivoanjo (Ivo Anjo) via ruby-core" <ruby-core@...>

Issue #20586 has been reported by ivoanjo (Ivo Anjo).

13 messages 2024/06/19

[#118347] [Ruby master Bug#20587] dir.c calls blocking system calls while holding the GVL — "ivoanjo (Ivo Anjo) via ruby-core" <ruby-core@...>

Issue #20587 has been reported by ivoanjo (Ivo Anjo).

7 messages 2024/06/19

[#118360] [Ruby master Bug#20588] RangeError: integer 132186463059104 too big to convert to 'int' since cdf33ed5f37f9649c482c3ba1d245f0d80ac01ce with YJIT enabled — "yahonda (Yasuo Honda) via ruby-core" <ruby-core@...>

Issue #20588 has been reported by yahonda (Yasuo Honda).

10 messages 2024/06/20

[#118388] [Ruby master Feature#20594] A new String method to append bytes while preserving encoding — "byroot (Jean Boussier) via ruby-core" <ruby-core@...>

SXNzdWUgIzIwNTk0IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGJ5cm9vdCAoSmVhbiBCb3Vzc2llciku

32 messages 2024/06/25

[ruby-core:118153] [Ruby master Bug#20518] Escaped-newline in %W

From: "akr (Akira Tanaka) via ruby-core" <ruby-core@...>
Date: 2024-06-03 13:11:42 UTC
List: ruby-core #118153
Issue #20518 has been updated by akr (Akira Tanaka).


`%I` has the same issue.

```
% ruby -e '
p %I[a\
b c\x21d e#{6*7}f]'
[:"a\nb", :"c!d", :e42f]
% ruby -e '
p %i[a\
b c\x21d e#{6*7}f]'
[:"a\nb", :"c\\x21d", :"e\#{6*7}f"]
```

`%I` inteprets `\<newline>` as a newline, not line continuation.

----------------------------------------
Bug #20518: Escaped-newline in %W
https://bugs.ruby-lang.org/issues/20518#change-108592

* Author: akr (Akira Tanaka)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I found an escaped-newline in %W literal is interpreted as a newline character.

```
% ./ruby -e '
p %W[a\
b]'
["a\nb"]
```

I expected it to be interpreted as a line continuation but actually not.

I'm considering to describe `\<newline>` as a kind of escape sequence in the document.
(Related to https://bugs.ruby-lang.org/issues/20503#note-4 )
Unfortunately, this behavior contradicts: `\<newline>` doesn't behave as usual escape sequences.

Note that %W is interpolable string-array literal.
https://docs.ruby-lang.org/en/master/syntax/literals_rdoc.html#label-25w+and+-25W-3A+String-Array+Lite

"interpolable" means that interpolation and escape sequences are enabled.

Other escape sequences and interpolation work well.

```
% ./ruby -e '
p %W[a\
b c\x21d e#{6*7}f]'
["a\nb", "c!d", "e42f"]
```

`\x21` is interpreted as "!" and `#{6*7}` is iterpreted as "42".
It is the usual interpretation of escape sequences and interpolation.
But `\<newline>` is interpreted as "\n".
It is not the usual interpretation of escape sequences (line continuation).

It is interpreted as a line continuation in a double-quoted string:

``` 
% ./ruby -e '
p %Q[a\
b c\x21d e#{6*7}f]'
"ab c!d e42f"
```

`\<newline>` is interpreted as empty (line continuation) as expected.
`\x21` is interpreted as "!" and `#{6*7}` is interpreted as "42".

I found this behavior changed between Ruby 1.8.0 and 1.8.1.
Ruby 1.8.0 interprets `\<newline>` as line continuation.

```
% ruby-1.8.0 -e '
p %W[a\
b c\x21d e#{6*7}f]'
["ab", "c!d", "e42f"]
% ruby-1.8.1 -e '
p %W[a\
b c\x21d e#{6*7}f]'
["a\nb", "c!d", "e42f"]
```

I think this is the commit to change the behavior.

```
commit e168b64b03403fb4efbd8dcbbdaeed83710b4d39 0d1896a88fe091000ce0d9c8ef3cf7ef1e2e991b
Author: Nobuyoshi Nakada <nobu@ruby-lang.org>
Date:   2003-09-04 14:59:43 +0000

    * parse.y (tokadd_string): newlines have no special meanings in
      %w/%W, otherwise they are ignored only when interpolation is
      enabled.  [ruby-dev:21325]


    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
```

I read the discussion from [ruby-dev:21325].
https://public-inbox.org/ruby-dev/5FD2F0CF7F5D7F44B00F36870B9E78B508DE5071@SBG-EX4/

It discusses about %w.
%W is not considered well.

The behavior of %w is also changed between Ruby 1.8.0 and 1.8.1.

```
% ruby-1.8.0 -e '
p %w[a\
b c\x21d e#{6*7}f]'
["ab", "c\\x21d", "e#{6*7}f"]
% ruby-1.8.1 -e '
p %w[a\
b c\x21d e#{6*7}f]'
["a\nb", "c\\x21d", "e#{6*7}f"]
```
I understand the intent of this behavior for %w: it makes it possible to include white spaces in the word.
Without this behavior, there is no way to include a newline character in the word.

But I don't understand the intent for %W.
Including a newline character using `\n` is possible because escape sequences are enabled.

```
% ./ruby -v
ruby 3.4.0dev (2024-05-25T10:15:25Z master 0bae2f0002) [x86_64-linux]
```



-- 
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/

In This Thread

Prev Next