ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
From
String#undump
to
String#unescape
”ÈÌÙ¤¿¤À¤·¤¿¤À¤·
Tadashi Saito
Do you know
String#undump ?
New (unknown)
built-in method in
Ruby 2.5
[bug#12275]
What?
"Does inverse of
String#dump"
end
³§´Ç¡­
Do you know
String#dump ?
From the document:
Produces a version of str with
all non-printing characters
replaced by nnn notation and
all special characters escaped.
In short:
Escape to
printable ASCII
Then,
String#undump
(almost) does
unescape from
printable ASCII
Escape format
example
1. backslash + one character n t 
2. x + 2 hex digits x12
3. u + 4 hex digits u1234
etc etc...
because notations used
in #dump is commonly
used among various
languages
#undump is useful
I saw first
these in C
Ruby Python
Java C# JSON
Nginx¡­
£ßÈËÈËÈËÈËÈËÈËÈËÈËÈË£ß
£¾¡¡Suddenly Nginx¡¡£¼
£þY^Y^Y^Y^Y^Y^Y^Y£þ
In fact, Nginx was
my trigger to
implement
String#undump
"We need to implement
String#undump to read access log
that Nginx writes"
Nginx module
ngx_http_log_module
(access_log, log_format)
spec:
Access: /api/{URL-escaped-mbchars}
Automatically!
Access: /api/{URL-escaped-mbchars}
¡ý
Internally: /api/{raw-mbchars}
Automatically!
Access: /api/{URL-escaped-mbchars}
¡ý
Internally: /api/{raw-mbchars}
¡ý
Log: /api/{xnn-escaped-mbchars}
Automatically!
Access log
looks like:
/api/xe3x81x82xe3x81x82xe3x81x82xe3x81x82
/api/xe3x81x84xe3x81x84xe3x81x84xe3x81x84
/api/xe3x81x86xe3x81x86xe3x81x86xe3x81x86
/api/xe3x81x88xe3x81x88xe3x81x88xe3x81x88
/api/xe3x81x8axe3x81x8axe3x81x8axe3x81x8a
/api/xe3x81x8bxe3x81x8bxe3x81x8bxe3x81x8b
/api/xe3x81x8dxe3x81x8dxe3x81x8dxe3x81x8d
/api/xe3x81x8fxe3x81x8fxe3x81x8fxe3x81x8f
/api/xe3x81x91xe3x81x91xe3x81x91xe3x81x91
/api/xe3x81x93xe3x81x93xe3x81x93xe3x81x93
:
:
:
:
I CAN NOT
READ
for analysis ?
£ßÈËÈËÈËÈËÈËÈËÈËÈËÈËÈËÈËÈËÈËÈË£ß
£¾ Can't change this behavior!! £¼
£þY^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y£þ
(at that time at least)
?  Decode with
Ruby!
1. Write it by
myself
Easily done,
but...
Too common
problem to
implement by
myself?
2. Google it for
gems / codes
No gems ?
Stack Overflow:
Loose and partially
incomplete
codes ?
3. Final means:
Google it in
bugs.ruby-lang.org
Ticket found!
[bug#12275]
¡ñ
Submitted about
a year ago
¡ñ
Specs (including the name
¨C most difficult part) were
almost fixed! ?
Matz:
"If someone
implement,
it's OK to add."
But no one
implements...
?  ?  Chance
to commit!
I messed up
and worked
Shipped as
built-in String
method in
Ruby 2.5! ?
Thank you for
involved committer /
adviser (especially
@naruse)
puts
¡®/api/xe3x81x82¡¯.undump
#=> RuntimeError
(invalid dumped
string...)
¡ñ
undump-ed string must
be wrapped with "¡­"
like ¡®¡±u1234¡±¡¯
¡ñ
Because String#dump
always wraps with "..."
String#undump Spec
Reasonable as spec of
"inverse of #dump",
but...
I have a little
regret
(to be honest)
¡ñ
A little dull to prepend / append ¡±
¡ñ
Both of the original use-case and
my case don't need this behavior
Plan to
improve?
1. Extend existing spec like
str.undump(allow_no_quotes: true)
Too long!
2. Introduce new method like
str.just_unescape_backslashed_chars
Hard way to
find good
name...
So I created a
(personal) gem
string_unescape
https://github.com/tadd/string_unescape
if self[0] == '"' && self[-1] == '"¡¯
self
else
¡®"¡¯ + self + ¡®¡±¡¯
end.undump
Definition
puts
'/api/xe3x81x82'.unescape
#=> /api/¤¢
Easy ?
Problems
¡ñ
The name may have arguments
¨C Hard to merge into the core
¡ñ
But just works?
¡ñ
From business knowledge,
¡ñ
Found a potential
and generic problem
¡ñ
Implemented as
(core / external) method
Summary of What I did
Please make use
¡ñ
String#undump (built-in)
&
¡ñ
String#unescape
(string_unescape gem)
more!!1
Ad

Recommended

Groovy / comparison with java
Groovy / comparison with java
Liviu Tudor
?
Airbnb Javascript Style Guide
Airbnb Javascript Style Guide
Creative Partners
?
Concurrency patterns in Ruby
Concurrency patterns in Ruby
ThoughtWorks
?
Building Ruby in Smalltalk
Building Ruby in Smalltalk
ESUG
?
Basics of Metaprogramming in Ruby
Basics of Metaprogramming in Ruby
Digital Natives
?
Calabash automated test
Calabash automated test
kellinreaver
?
JavaScript iteration
JavaScript iteration
Charles Russell
?
CoffeeScript - An Introduction
CoffeeScript - An Introduction
Manvendra Singh
?
printf tricks
printf tricks
Shaun Colley
?
RSpec 3.0: Under the Covers
RSpec 3.0: Under the Covers
Brian Gesiak
?
Write Your Own JVM Compiler
Write Your Own JVM Compiler
Erin Dees
?
A tutorial introduction to the unix text editor ed
A tutorial introduction to the unix text editor ed
Humberto Garay
?
name name2 n2.ppt
name name2 n2.ppt
callroom
?
Ruby for Perl Programmers
Ruby for Perl Programmers
amiable_indian
?
ppt2
ppt2
callroom
?
name name2 n
name name2 n
callroom
?
name name2 n2
name name2 n2
callroom
?
ppt30
ppt30
callroom
?
name name2 n
name name2 n
callroom
?
ppt21
ppt21
callroom
?
name name2 n
name name2 n
callroom
?
ppt17
ppt17
callroom
?
ppt7
ppt7
callroom
?
ppt9
ppt9
callroom
?
test ppt
test ppt
callroom
?
ppt18
ppt18
callroom
?
Rust All Hands Winter 2011
Rust All Hands Winter 2011
Patrick Walton
?
ElixirConf 2017 - Writing an Editor in Elixir - Ian Duggan
ElixirConf 2017 - Writing an Editor in Elixir - Ian Duggan
ijcd
?
¸é²¹³Ù¾±´Ç²Ô²¹±ô¤ò(¤â¤¦¤Á¤ç¤Ã¤È)×îÊÊ»¯¤·¤Æ¤ß¤¿
¸é²¹³Ù¾±´Ç²Ô²¹±ô¤ò(¤â¤¦¤Á¤ç¤Ã¤È)×îÊÊ»¯¤·¤Æ¤ß¤¿
Tadashi Saito
?
¸é²¹³Ù¾±´Ç²Ô²¹±ô¤ò×îÊÊ»¯¤·¤Æ¤ß¤¿
¸é²¹³Ù¾±´Ç²Ô²¹±ô¤ò×îÊÊ»¯¤·¤Æ¤ß¤¿
Tadashi Saito
?

More Related Content

Similar to From String#undump to String#unescape (20)

printf tricks
printf tricks
Shaun Colley
?
RSpec 3.0: Under the Covers
RSpec 3.0: Under the Covers
Brian Gesiak
?
Write Your Own JVM Compiler
Write Your Own JVM Compiler
Erin Dees
?
A tutorial introduction to the unix text editor ed
A tutorial introduction to the unix text editor ed
Humberto Garay
?
name name2 n2.ppt
name name2 n2.ppt
callroom
?
Ruby for Perl Programmers
Ruby for Perl Programmers
amiable_indian
?
ppt2
ppt2
callroom
?
name name2 n
name name2 n
callroom
?
name name2 n2
name name2 n2
callroom
?
ppt30
ppt30
callroom
?
name name2 n
name name2 n
callroom
?
ppt21
ppt21
callroom
?
name name2 n
name name2 n
callroom
?
ppt17
ppt17
callroom
?
ppt7
ppt7
callroom
?
ppt9
ppt9
callroom
?
test ppt
test ppt
callroom
?
ppt18
ppt18
callroom
?
Rust All Hands Winter 2011
Rust All Hands Winter 2011
Patrick Walton
?
ElixirConf 2017 - Writing an Editor in Elixir - Ian Duggan
ElixirConf 2017 - Writing an Editor in Elixir - Ian Duggan
ijcd
?
RSpec 3.0: Under the Covers
RSpec 3.0: Under the Covers
Brian Gesiak
?
Write Your Own JVM Compiler
Write Your Own JVM Compiler
Erin Dees
?
A tutorial introduction to the unix text editor ed
A tutorial introduction to the unix text editor ed
Humberto Garay
?
name name2 n2.ppt
name name2 n2.ppt
callroom
?
Ruby for Perl Programmers
Ruby for Perl Programmers
amiable_indian
?
name name2 n2
name name2 n2
callroom
?
Rust All Hands Winter 2011
Rust All Hands Winter 2011
Patrick Walton
?
ElixirConf 2017 - Writing an Editor in Elixir - Ian Duggan
ElixirConf 2017 - Writing an Editor in Elixir - Ian Duggan
ijcd
?

More from Tadashi Saito (6)

¸é²¹³Ù¾±´Ç²Ô²¹±ô¤ò(¤â¤¦¤Á¤ç¤Ã¤È)×îÊÊ»¯¤·¤Æ¤ß¤¿
¸é²¹³Ù¾±´Ç²Ô²¹±ô¤ò(¤â¤¦¤Á¤ç¤Ã¤È)×îÊÊ»¯¤·¤Æ¤ß¤¿
Tadashi Saito
?
¸é²¹³Ù¾±´Ç²Ô²¹±ô¤ò×îÊÊ»¯¤·¤Æ¤ß¤¿
¸é²¹³Ù¾±´Ç²Ô²¹±ô¤ò×îÊÊ»¯¤·¤Æ¤ß¤¿
Tadashi Saito
?
Ruby±¾¤«¤éÕi¤ß½â¤¯Ruby¿¼¹Åѧ - Ruby Archaeology from the Ruby Book
Ruby±¾¤«¤éÕi¤ß½â¤¯Ruby¿¼¹Åѧ - Ruby Archaeology from the Ruby Book
Tadashi Saito
?
Ô”½â! Decimal
Ô”½â! Decimal
Tadashi Saito
?
’ˆÕť饤¥Ö¥é¥ê¤ò×÷¤ë¤È¥ê¥¢³ä
’ˆÕť饤¥Ö¥é¥ê¤ò×÷¤ë¤È¥ê¥¢³ä
Tadashi Saito
?
´ÎÊÀ´úÊý‚ŽÑÝË㠥饤¥Ö¥é¥ê Decimal ¤È¤¤¤¦ÔÙ°kÃ÷¤ÎÒâÁx
´ÎÊÀ´úÊý‚ŽÑÝË㠥饤¥Ö¥é¥ê Decimal ¤È¤¤¤¦ÔÙ°kÃ÷¤ÎÒâÁx
Tadashi Saito
?
¸é²¹³Ù¾±´Ç²Ô²¹±ô¤ò(¤â¤¦¤Á¤ç¤Ã¤È)×îÊÊ»¯¤·¤Æ¤ß¤¿
¸é²¹³Ù¾±´Ç²Ô²¹±ô¤ò(¤â¤¦¤Á¤ç¤Ã¤È)×îÊÊ»¯¤·¤Æ¤ß¤¿
Tadashi Saito
?
¸é²¹³Ù¾±´Ç²Ô²¹±ô¤ò×îÊÊ»¯¤·¤Æ¤ß¤¿
¸é²¹³Ù¾±´Ç²Ô²¹±ô¤ò×îÊÊ»¯¤·¤Æ¤ß¤¿
Tadashi Saito
?
Ruby±¾¤«¤éÕi¤ß½â¤¯Ruby¿¼¹Åѧ - Ruby Archaeology from the Ruby Book
Ruby±¾¤«¤éÕi¤ß½â¤¯Ruby¿¼¹Åѧ - Ruby Archaeology from the Ruby Book
Tadashi Saito
?
’ˆÕť饤¥Ö¥é¥ê¤ò×÷¤ë¤È¥ê¥¢³ä
’ˆÕť饤¥Ö¥é¥ê¤ò×÷¤ë¤È¥ê¥¢³ä
Tadashi Saito
?
´ÎÊÀ´úÊý‚ŽÑÝË㠥饤¥Ö¥é¥ê Decimal ¤È¤¤¤¦ÔÙ°kÃ÷¤ÎÒâÁx
´ÎÊÀ´úÊý‚ŽÑÝË㠥饤¥Ö¥é¥ê Decimal ¤È¤¤¤¦ÔÙ°kÃ÷¤ÎÒâÁx
Tadashi Saito
?
Ad

Recently uploaded (20)

Azure AI Foundry: The AI app and agent factory
Azure AI Foundry: The AI app and agent factory
Maxim Salnikov
?
Best Practice for LLM Serving in the Cloud
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
?
Advance Doctor Appointment Booking App With Online Payment
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
?
Folding Cheat Sheet # 9 - List Unfolding ?????? as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding ?????? as the Computational Dual of ...
Philip Schwarz
?
How Automation in Claims Handling Streamlined Operations
How Automation in Claims Handling Streamlined Operations
Insurance Tech Services
?
Download Adobe Illustrator Crack free for Windows 2025?
Download Adobe Illustrator Crack free for Windows 2025?
grete1122g
?
Canva Pro Crack Free Download 2025-FREE LATEST
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
?
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
WSO2
?
Why Edge Computing Matters in Mobile Application Tech.pdf
Why Edge Computing Matters in Mobile Application Tech.pdf
IMG Global Infotech
?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
?
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
?
Humans vs AI Call Agents - Qcall.ai's Special Report
Humans vs AI Call Agents - Qcall.ai's Special Report
Udit Goenka
?
Decipher SEO Solutions for your startup needs.
Decipher SEO Solutions for your startup needs.
mathai2
?
IObit Driver Booster Pro 12 Crack Latest Version Download
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
?
Heat Treatment Process Automation in India
Heat Treatment Process Automation in India
Reckers Mechatronics
?
Y - Recursion The Hard Way GopherCon EU 2025
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
?
Simplify Insurance Regulations with Compliance Management Software
Simplify Insurance Regulations with Compliance Management Software
Insurance Tech Services
?
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
?
A Guide to Telemedicine Software Development.pdf
A Guide to Telemedicine Software Development.pdf
Olivero Bozzelli
?
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
?
Azure AI Foundry: The AI app and agent factory
Azure AI Foundry: The AI app and agent factory
Maxim Salnikov
?
Best Practice for LLM Serving in the Cloud
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
?
Advance Doctor Appointment Booking App With Online Payment
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
?
Folding Cheat Sheet # 9 - List Unfolding ?????? as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding ?????? as the Computational Dual of ...
Philip Schwarz
?
How Automation in Claims Handling Streamlined Operations
How Automation in Claims Handling Streamlined Operations
Insurance Tech Services
?
Download Adobe Illustrator Crack free for Windows 2025?
Download Adobe Illustrator Crack free for Windows 2025?
grete1122g
?
Canva Pro Crack Free Download 2025-FREE LATEST
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
?
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
WSO2
?
Why Edge Computing Matters in Mobile Application Tech.pdf
Why Edge Computing Matters in Mobile Application Tech.pdf
IMG Global Infotech
?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
?
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
?
Humans vs AI Call Agents - Qcall.ai's Special Report
Humans vs AI Call Agents - Qcall.ai's Special Report
Udit Goenka
?
Decipher SEO Solutions for your startup needs.
Decipher SEO Solutions for your startup needs.
mathai2
?
IObit Driver Booster Pro 12 Crack Latest Version Download
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
?
Heat Treatment Process Automation in India
Heat Treatment Process Automation in India
Reckers Mechatronics
?
Y - Recursion The Hard Way GopherCon EU 2025
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
?
Simplify Insurance Regulations with Compliance Management Software
Simplify Insurance Regulations with Compliance Management Software
Insurance Tech Services
?
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
?
A Guide to Telemedicine Software Development.pdf
A Guide to Telemedicine Software Development.pdf
Olivero Bozzelli
?
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
?
Ad

From String#undump to String#unescape