Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 48e3866

Browse files
committed
Only unescape forward slashes in regular expressions if converting from slash bounds to %r bounds.
1 parent 391bf14 commit 48e3866

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
4040
- Ensure the `Return` breaks with brackets and not parentheses.
4141
- Ensure trailing comments on parameter declarations are consistent.
4242
- Make `Command` and `CommandCall` aware that their arguments could exceed their normal expected bounds because of heredocs.
43+
- Only unescape forward slashes in regular expressions if converting from slash bounds to `%r` bounds.
4344

4445
### Removed
4546

lib/syntax_tree.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9755,12 +9755,18 @@ def format(q)
97559755
q.group do
97569756
q.text("%r{")
97579757

9758-
parts.each do |part|
9759-
if part.is_a?(TStringContent)
9760-
q.text(part.value.gsub("\\/", "/"))
9761-
else
9762-
q.format(part)
9758+
if beginning == "/"
9759+
# If we're changing from a forward slash to a %r{, then we can
9760+
# replace any escaped forward slashes with regular forward slashes.
9761+
parts.each do |part|
9762+
if part.is_a?(TStringContent)
9763+
q.text(part.value.gsub("\\/", "/"))
9764+
else
9765+
q.format(part)
9766+
end
97639767
end
9768+
else
9769+
q.format_each(parts)
97649770
end
97659771

97669772
q.text("}")

0 commit comments

Comments
 (0)