ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:69063] [Ruby trunk - Bug #11116] [Open] The spec of String#dump
       [not found] <redmine.issue-11116.20150503103632@ruby-lang.org>
@ 2015-05-03 10:36 ` mame
  2019-01-21  8:52 ` [ruby-core:91207] [Ruby trunk Bug#11116] " mame
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: mame @ 2015-05-03 10:36 UTC (permalink / raw
  To: ruby-core

Issue #11116 has been reported by Yusuke Endoh.

----------------------------------------
Bug #11116: The spec of String#dump
https://bugs.ruby-lang.org/issues/11116

* Author: Yusuke Endoh
* Status: Open
* Priority: Normal
* Assignee: Yusuke Endoh
* ruby -v: ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
The current spec says:

     call-seq:
       str.dump   -> new_str

    Produces a version of +str+ with all non-printing characters replaced by
    <code>\nnn</code> notation and all special characters escaped.

      "hello \n ''".dump  #=> "\"hello \\n ''\"

`\nnn` must be `\xnn` now.

In addition, I've expected String#dump to return a string that evaluates to an original string (except singleton methods, object id, etc.) when `eval`ed.  Is this a right expectation?  If so, it would be good to officially include the mention in the spec.  What do you think?

-- 
Yusuke Endoh <mame@ruby-lang.org>



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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:91207] [Ruby trunk Bug#11116] The spec of String#dump
       [not found] <redmine.issue-11116.20150503103632@ruby-lang.org>
  2015-05-03 10:36 ` [ruby-core:69063] [Ruby trunk - Bug #11116] [Open] The spec of String#dump mame
@ 2019-01-21  8:52 ` mame
  2019-01-21 10:54 ` [ruby-core:91210] " eregontp
  2019-01-21 13:20 ` [ruby-core:91212] " mame
  3 siblings, 0 replies; 4+ messages in thread
From: mame @ 2019-01-21  8:52 UTC (permalink / raw
  To: ruby-core

Issue #11116 has been updated by mame (Yusuke Endoh).

Status changed from Open to Closed

Committed at r66894.  Closing

----------------------------------------
Bug #11116: The spec of String#dump
https://bugs.ruby-lang.org/issues/11116#change-76444

* Author: mame (Yusuke Endoh)
* Status: Closed
* Priority: Normal
* Assignee: mame (Yusuke Endoh)
* Target version: 
* ruby -v: ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
The current spec says:

     call-seq:
       str.dump   -> new_str

    Produces a version of +str+ with all non-printing characters replaced by
    <code>\nnn</code> notation and all special characters escaped.

      "hello \n ''".dump  #=> "\"hello \\n ''\"

`\nnn` must be `\xnn` now.

In addition, I've expected String#dump to return a string that evaluates to an original string (except singleton methods, object id, etc.) when `eval`ed.  Is this a right expectation?  If so, it would be good to officially include the mention in the spec.  What do you think?

-- 
Yusuke Endoh <mame@ruby-lang.org>



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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:91210] [Ruby trunk Bug#11116] The spec of String#dump
       [not found] <redmine.issue-11116.20150503103632@ruby-lang.org>
  2015-05-03 10:36 ` [ruby-core:69063] [Ruby trunk - Bug #11116] [Open] The spec of String#dump mame
  2019-01-21  8:52 ` [ruby-core:91207] [Ruby trunk Bug#11116] " mame
@ 2019-01-21 10:54 ` eregontp
  2019-01-21 13:20 ` [ruby-core:91212] " mame
  3 siblings, 0 replies; 4+ messages in thread
From: eregontp @ 2019-01-21 10:54 UTC (permalink / raw
  To: ruby-core

Issue #11116 has been updated by Eregon (Benoit Daloze).


Does that preserve the encoding of the String though?

What about String#inspect, does it also eval() to itself?

----------------------------------------
Bug #11116: The spec of String#dump
https://bugs.ruby-lang.org/issues/11116#change-76448

* Author: mame (Yusuke Endoh)
* Status: Closed
* Priority: Normal
* Assignee: mame (Yusuke Endoh)
* Target version: 
* ruby -v: ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
The current spec says:

     call-seq:
       str.dump   -> new_str

    Produces a version of +str+ with all non-printing characters replaced by
    <code>\nnn</code> notation and all special characters escaped.

      "hello \n ''".dump  #=> "\"hello \\n ''\"

`\nnn` must be `\xnn` now.

In addition, I've expected String#dump to return a string that evaluates to an original string (except singleton methods, object id, etc.) when `eval`ed.  Is this a right expectation?  If so, it would be good to officially include the mention in the spec.  What do you think?

-- 
Yusuke Endoh <mame@ruby-lang.org>



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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:91212] [Ruby trunk Bug#11116] The spec of String#dump
       [not found] <redmine.issue-11116.20150503103632@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-01-21 10:54 ` [ruby-core:91210] " eregontp
@ 2019-01-21 13:20 ` mame
  3 siblings, 0 replies; 4+ messages in thread
From: mame @ 2019-01-21 13:20 UTC (permalink / raw
  To: ruby-core

Issue #11116 has been updated by mame (Yusuke Endoh).


Eregon (Benoit Daloze) wrote:
> Does that preserve the encoding of the String though?

The short answer: yes.

If the encoding is ASCII-compatible, it is preserved via its encoding of the resulting string.

```
s = "Hello こんにちは".encode("Windows-31J")
s = s.dump
puts s                 #=> "Hello \x82\xB1\x82\xF1\x82\xC9\x82\xBF\x82\xCD"
p s.encoding           #=> #<Encoding:Windows-31J>
s = eval(s)
p s.encoding           #=> #<Encoding:Windows-31J>
puts s.encode("UTF-8") #=> Hello こんにちは
```

If the encoding is not ASCII-compatible, the dumped string has an explicit `force_encoding`.

```
s = "Hello こんにちは".encode("UTF-16LE")
s = s.dump
puts s                 #=> "H\x00e\x00l\x00l\x00o\x00 \x00S0\x930k0a0o0".dup.force_encoding("UTF-16LE")
s = eval(s)
puts s.encode("UTF-8") #=> Hello こんにちは
```

I guess that there might be other subtle edge cases that I don't know.  It is difficult for me to write the detailed document.


> What about String#inspect, does it also eval() to itself?

No, it is not guaranteed.  `String#inspect` is just for human, so there is no annoying hack like the above non-ASCII-compatible encoding.  (I have encountered another subtle case, but I cannot remember...)

----------------------------------------
Bug #11116: The spec of String#dump
https://bugs.ruby-lang.org/issues/11116#change-76450

* Author: mame (Yusuke Endoh)
* Status: Closed
* Priority: Normal
* Assignee: mame (Yusuke Endoh)
* Target version: 
* ruby -v: ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
The current spec says:

     call-seq:
       str.dump   -> new_str

    Produces a version of +str+ with all non-printing characters replaced by
    <code>\nnn</code> notation and all special characters escaped.

      "hello \n ''".dump  #=> "\"hello \\n ''\"

`\nnn` must be `\xnn` now.

In addition, I've expected String#dump to return a string that evaluates to an original string (except singleton methods, object id, etc.) when `eval`ed.  Is this a right expectation?  If so, it would be good to officially include the mention in the spec.  What do you think?

-- 
Yusuke Endoh <mame@ruby-lang.org>



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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-01-21 13:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-11116.20150503103632@ruby-lang.org>
2015-05-03 10:36 ` [ruby-core:69063] [Ruby trunk - Bug #11116] [Open] The spec of String#dump mame
2019-01-21  8:52 ` [ruby-core:91207] [Ruby trunk Bug#11116] " mame
2019-01-21 10:54 ` [ruby-core:91210] " eregontp
2019-01-21 13:20 ` [ruby-core:91212] " mame

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).