From: tad.a.digger@... Date: 2017-12-13T20:44:46+00:00 Subject: [ruby-core:84242] [Ruby trunk Feature#12275] String unescape Issue #12275 has been updated by tad (Tadashi Saito). File v3.patch added Thanks to shyouhei, mame, and especially naruse, I was able to brush up the patch. v3.patch is attached. Improvements are diverse. Spec change: * use RuntimeError instead of ArgumentError for invalid formed (self) string * no arguments are given for this method... :( * explicitly reject string that contains: * non-ascii character * NUL `\0` character * (note that `dump`ed strings do not contain above) Bug fix: * reject string that contains double quote in double quotes, like `'""""'` * prevent compiler's warnings/errors * cast explicitly from unsigned long to int * remove needless "const" Misc: * fix styles * add more tests for invalid escaping * remove needless logic * adjust unescaped expression to parse.y I'll take a short nap while praying so that AFL will not catch the worm... ---------------------------------------- Feature #12275: String unescape https://bugs.ruby-lang.org/issues/12275#change-68371 * Author: asnow (Andrew Bolshov) * Status: Assigned * Priority: Normal * Assignee: tad (Tadashi Saito) * Target version: ---------------------------------------- I think it will be usefull to have function that convert input string as it was written in prime qouted string or in double qouted string. It's part of metaprogramming. Example: ~~~ ruby class String # Create new string like it will be writed in qoutes. Optional argument define type of qouting used: true - prime qoute, false - double qoute. Default is double qoute. def unescape prime = false eval( prime ? "'#{self}'" : "\"#{self}\"" ) end end "\\\t".unescape # => "\t" ~~~ Other requests: http://www.rubydoc.info/github/ronin-ruby/ronin-support/String:unescape http://stackoverflow.com/questions/4265928/how-do-i-unescape-c-style-escape-sequences-from-ruby http://stackoverflow.com/questions/8639642/best-way-to-escape-and-unescape-strings-in-ruby Realized http://www.rubydoc.info/github/ronin-ruby/ronin-support/String:unescape ---Files-------------------------------- benchmark.rb (193 Bytes) v1.patch (8.95 KB) benchmark2.rb (315 Bytes) v2.patch (12.1 KB) v3.patch (12.9 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: