ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:99528] [Ruby master Bug#17110] String.tr unexpected behaviour with backslash
@ 2020-08-10  3:00 entpman
  2020-08-10  3:01 ` [ruby-core:99529] " entpman
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: entpman @ 2020-08-10  3:00 UTC (permalink / raw)
  To: ruby-core

Issue #17110 has been reported by theplen (Joey Sheets).

----------------------------------------
Bug #17110: String.tr unexpected behaviour with backslash
https://bugs.ruby-lang.org/issues/17110

* Author: theplen (Joey Sheets)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
"\\".tr("\\","A")  works great, with "\\" becoming "A"

"\\".tr("\\C","AB") should also output "A" but instead outputs "\\"




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

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

* [ruby-core:99529] [Ruby master Bug#17110] String.tr unexpected behaviour with backslash
  2020-08-10  3:00 [ruby-core:99528] [Ruby master Bug#17110] String.tr unexpected behaviour with backslash entpman
@ 2020-08-10  3:01 ` entpman
  2020-08-10  5:35 ` [ruby-core:99531] " mame
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: entpman @ 2020-08-10  3:01 UTC (permalink / raw)
  To: ruby-core

Issue #17110 has been updated by theplen (Joey Sheets).


``` ruby
"\\".tr("\\","A") works great, with "\\" becoming "A"

"\\".tr("\\C","AB") should also output "A" but instead outputs "\\"
```


----------------------------------------
Bug #17110: String.tr unexpected behaviour with backslash
https://bugs.ruby-lang.org/issues/17110#change-86989

* Author: theplen (Joey Sheets)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
"\\".tr("\\","A")  works great, with "\\" becoming "A"

"\\".tr("\\C","AB") should also output "A" but instead outputs "\\"




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

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

* [ruby-core:99531] [Ruby master Bug#17110] String.tr unexpected behaviour with backslash
  2020-08-10  3:00 [ruby-core:99528] [Ruby master Bug#17110] String.tr unexpected behaviour with backslash entpman
  2020-08-10  3:01 ` [ruby-core:99529] " entpman
@ 2020-08-10  5:35 ` mame
  2020-08-10  7:09 ` [ruby-core:99533] " entpman
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: mame @ 2020-08-10  5:35 UTC (permalink / raw)
  To: ruby-core

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

Status changed from Open to Rejected

See the document.

> The backslash character `\` can be used to escape `^` or `-` and is otherwise ignored unless it appears at the end of a range or the end of the from_str or to_str:

https://docs.ruby-lang.org/en/2.7.0/String.html#method-i-tr

So you can write `"\\".tr("C\\", "BA")` according to the document.

This seems undocumented, but `\` can be used to escape `\`, so you can also write `"\\".tr("\\\\C", "AN")`.

----------------------------------------
Bug #17110: String.tr unexpected behaviour with backslash
https://bugs.ruby-lang.org/issues/17110#change-86991

* Author: theplen (Joey Sheets)
* Status: Rejected
* Priority: Normal
* ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
`"\\".tr("\\","A")` works great, with `"\\"` becoming `"A"`.

`"\\".tr("\\C","AB")` should also output `"A"`, but instead outputs `"\\"`.



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

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

* [ruby-core:99533] [Ruby master Bug#17110] String.tr unexpected behaviour with backslash
  2020-08-10  3:00 [ruby-core:99528] [Ruby master Bug#17110] String.tr unexpected behaviour with backslash entpman
  2020-08-10  3:01 ` [ruby-core:99529] " entpman
  2020-08-10  5:35 ` [ruby-core:99531] " mame
@ 2020-08-10  7:09 ` entpman
  2020-08-10  8:18 ` [ruby-core:99535] " mame
  2020-08-10 14:51 ` [ruby-core:99543] " entpman
  4 siblings, 0 replies; 6+ messages in thread
From: entpman @ 2020-08-10  7:09 UTC (permalink / raw)
  To: ruby-core

Issue #17110 has been updated by theplen (Joey Sheets).


Is there no way to do change all backslashes to forward slashes and forward slashes to backslashes in the same tr command?  

``` ruby
# Should result in "/\\" but instead results in "\\/" (unchanged)
"\\/".tr("\//","\\/")
```




----------------------------------------
Bug #17110: String.tr unexpected behaviour with backslash
https://bugs.ruby-lang.org/issues/17110#change-86993

* Author: theplen (Joey Sheets)
* Status: Rejected
* Priority: Normal
* ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
`"\\".tr("\\","A")` works great, with `"\\"` becoming `"A"`.

`"\\".tr("\\C","AB")` should also output `"A"`, but instead outputs `"\\"`.



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

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

* [ruby-core:99535] [Ruby master Bug#17110] String.tr unexpected behaviour with backslash
  2020-08-10  3:00 [ruby-core:99528] [Ruby master Bug#17110] String.tr unexpected behaviour with backslash entpman
                   ` (2 preceding siblings ...)
  2020-08-10  7:09 ` [ruby-core:99533] " entpman
@ 2020-08-10  8:18 ` mame
  2020-08-10 14:51 ` [ruby-core:99543] " entpman
  4 siblings, 0 replies; 6+ messages in thread
From: mame @ 2020-08-10  8:18 UTC (permalink / raw)
  To: ruby-core

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


```
p "\\/".tr("/\\\\", "\\\\/") #=> "/\\"
```

Unfortunately it is complicated, but `\` is an escape character of string literal as well as an escape character of `String#tr` format, so it is unavoidable.

----------------------------------------
Bug #17110: String.tr unexpected behaviour with backslash
https://bugs.ruby-lang.org/issues/17110#change-86995

* Author: theplen (Joey Sheets)
* Status: Rejected
* Priority: Normal
* ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
`"\\".tr("\\","A")` works great, with `"\\"` becoming `"A"`.

`"\\".tr("\\C","AB")` should also output `"A"`, but instead outputs `"\\"`.



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

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

* [ruby-core:99543] [Ruby master Bug#17110] String.tr unexpected behaviour with backslash
  2020-08-10  3:00 [ruby-core:99528] [Ruby master Bug#17110] String.tr unexpected behaviour with backslash entpman
                   ` (3 preceding siblings ...)
  2020-08-10  8:18 ` [ruby-core:99535] " mame
@ 2020-08-10 14:51 ` entpman
  4 siblings, 0 replies; 6+ messages in thread
From: entpman @ 2020-08-10 14:51 UTC (permalink / raw)
  To: ruby-core

Issue #17110 has been updated by theplen (Joey Sheets).


Yusuke Endoh, thanks for clearing it up.

----------------------------------------
Bug #17110: String.tr unexpected behaviour with backslash
https://bugs.ruby-lang.org/issues/17110#change-87003

* Author: theplen (Joey Sheets)
* Status: Rejected
* Priority: Normal
* ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
`"\\".tr("\\","A")` works great, with `"\\"` becoming `"A"`.

`"\\".tr("\\C","AB")` should also output `"A"`, but instead outputs `"\\"`.



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

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

end of thread, other threads:[~2020-08-10 14:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-10  3:00 [ruby-core:99528] [Ruby master Bug#17110] String.tr unexpected behaviour with backslash entpman
2020-08-10  3:01 ` [ruby-core:99529] " entpman
2020-08-10  5:35 ` [ruby-core:99531] " mame
2020-08-10  7:09 ` [ruby-core:99533] " entpman
2020-08-10  8:18 ` [ruby-core:99535] " mame
2020-08-10 14:51 ` [ruby-core:99543] " entpman

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).