Skip to content

Commit 7dcb07a

Browse files
committed
[GR-28734] Update glob left brace detection to handle escaped backslash case
PullRequest: truffleruby/2906
2 parents a7c63d3 + 66854f4 commit 7dcb07a

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

spec/ruby/core/dir/fixtures/common.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def self.mock_dir_files
9292
special/|
9393

9494
special/こんにちは.txt
95+
special/\a
9596
]
9697
end
9798
end

spec/ruby/core/dir/shared/glob.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
it "matches regexp special |" do
8181
Dir.send(@method, 'special/|').should == ['special/|']
8282
end
83+
84+
it "matches files with backslashes in their name" do
85+
Dir.glob('special/\\\\{a,b}').should == ['special/\a']
86+
end
8387
end
8488

8589
it "matches regexp special ^" do

src/main/ruby/truffleruby/core/dir_glob.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ def self.glob(base_dir, pattern, flags, matches)
455455
return matches
456456
end
457457

458-
left_brace_index = pattern.index(/(?<!\\){/)
458+
left_brace_match = pattern.match(/(\\*)(\{)/)
459+
left_brace_index = left_brace_match && left_brace_match[1].size.even? ? left_brace_match.begin(2) : nil
459460
if left_brace_index
460461
patterns = compile(pattern, left_brace_index, flags)
461462

0 commit comments

Comments
 (0)