SlideShare a Scribd company logo
1 of 64
Download to read offline
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
So…
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
– 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
– 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

More Related Content

Similar to From String#undump to String#unescape

RSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversBrian Gesiak
 
Write Your Own JVM Compiler
Write Your Own JVM CompilerWrite Your Own JVM Compiler
Write Your Own JVM CompilerErin Dees
 
A tutorial introduction to the unix text editor ed
A tutorial introduction to the unix text editor edA tutorial introduction to the unix text editor ed
A tutorial introduction to the unix text editor edHumberto Garay
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2
name name2 n2name name2 n2
name name2 n2callroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.pptcallroom
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmersamiable_indian
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011Patrick Walton
 
ElixirConf 2017 - Writing an Editor in Elixir - Ian Duggan
ElixirConf 2017 - Writing an Editor in Elixir - Ian DugganElixirConf 2017 - Writing an Editor in Elixir - Ian Duggan
ElixirConf 2017 - Writing an Editor in Elixir - Ian Dugganijcd
 

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

printf tricks
printf tricksprintf tricks
printf tricks
 
RSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the Covers
 
Write Your Own JVM Compiler
Write Your Own JVM CompilerWrite Your Own JVM Compiler
Write Your Own JVM Compiler
 
A tutorial introduction to the unix text editor ed
A tutorial introduction to the unix text editor edA tutorial introduction to the unix text editor ed
A tutorial introduction to the unix text editor ed
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 
ppt18
ppt18ppt18
ppt18
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 
ppt9
ppt9ppt9
ppt9
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011
 
ElixirConf 2017 - Writing an Editor in Elixir - Ian Duggan
ElixirConf 2017 - Writing an Editor in Elixir - Ian DugganElixirConf 2017 - Writing an Editor in Elixir - Ian Duggan
ElixirConf 2017 - Writing an Editor in Elixir - Ian Duggan
 

More from Tadashi Saito

Rationalを(もうちょっと)最適化してみた
Rationalを(もうちょっと)最適化してみたRationalを(もうちょっと)最適化してみた
Rationalを(もうちょっと)最適化してみたTadashi Saito
 
Rationalを最適化してみた
Rationalを最適化してみたRationalを最適化してみた
Rationalを最適化してみたTadashi Saito
 
Ruby本から読み解くRuby考古学 - Ruby Archaeology from the Ruby Book
Ruby本から読み解くRuby考古学 - Ruby Archaeology from the Ruby BookRuby本から読み解くRuby考古学 - Ruby Archaeology from the Ruby Book
Ruby本から読み解くRuby考古学 - Ruby Archaeology from the Ruby BookTadashi Saito
 
拡張ライブラリを作るとリア充
拡張ライブラリを作るとリア充拡張ライブラリを作るとリア充
拡張ライブラリを作るとリア充Tadashi Saito
 
次世代数値演算 ライブラリ Decimal という再発明の意義
次世代数値演算 ライブラリ Decimal という再発明の意義次世代数値演算 ライブラリ Decimal という再発明の意義
次世代数値演算 ライブラリ Decimal という再発明の意義Tadashi Saito
 

More from Tadashi Saito (6)

Rationalを(もうちょっと)最適化してみた
Rationalを(もうちょっと)最適化してみたRationalを(もうちょっと)最適化してみた
Rationalを(もうちょっと)最適化してみた
 
Rationalを最適化してみた
Rationalを最適化してみたRationalを最適化してみた
Rationalを最適化してみた
 
Ruby本から読み解くRuby考古学 - Ruby Archaeology from the Ruby Book
Ruby本から読み解くRuby考古学 - Ruby Archaeology from the Ruby BookRuby本から読み解くRuby考古学 - Ruby Archaeology from the Ruby Book
Ruby本から読み解くRuby考古学 - Ruby Archaeology from the Ruby Book
 
詳解! Decimal
詳解! Decimal詳解! Decimal
詳解! Decimal
 
拡張ライブラリを作るとリア充
拡張ライブラリを作るとリア充拡張ライブラリを作るとリア充
拡張ライブラリを作るとリア充
 
次世代数値演算 ライブラリ Decimal という再発明の意義
次世代数値演算 ライブラリ Decimal という再発明の意義次世代数値演算 ライブラリ Decimal という再発明の意義
次世代数値演算 ライブラリ Decimal という再発明の意義
 

Recently uploaded

Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?Watsoo Telematics
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 

Recently uploaded (20)

Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 

From String#undump to String#unescape