Skip to content

Commit 4f0134a

Browse files
committed
Fix issue with escaping curly braces for Dir.glob
1 parent 513d5e2 commit 4f0134a

File tree

5 files changed

+10
-1
lines changed

5 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Bug fixes:
2121
* Fix issue with `strspn` used in the `date` C extension compiled as a macro on older glibc and then missing the `__strspn_c1` symbol on newer glibc (#2406).
2222
* Fix constant lookup when loading the same file multiple times (#2408).
2323
* Fix handling of `break`, `next` and `redo` in `define_method(name, &block)` methods (#2418).
24+
* Fix issue with escaping curly braces for `Dir.glob` (#2425).
2425

2526
Compatibility:
2627

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def self.mock_dir_files
8181
special/}
8282

8383
special/test{1}/file[1]
84+
special/{}/special
8485
]
8586

8687
platform_is_not :windows do

spec/ruby/core/dir/glob_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
nested/.dotsubir/
8181
special/
8282
special/test{1}/
83+
special/{}/
8384
subdir_one/
8485
subdir_two/
8586
]
@@ -130,6 +131,7 @@
130131
./nested/.dotsubir/
131132
./special/
132133
./special/test{1}/
134+
./special/{}/
133135
./subdir_one/
134136
./subdir_two/
135137
]

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
Dir.send(@method, 'special/+').should == ['special/+']
6565
end
6666

67+
it "matches directories with special characters when escaped" do
68+
Dir.send(@method, 'special/\{}/special').should == ["special/{}/special"]
69+
end
70+
6771
platform_is_not :windows do
6872
it "matches regexp special *" do
6973
Dir.send(@method, 'special/\*').should == ['special/*']
@@ -191,6 +195,7 @@
191195
nested/
192196
special/
193197
special/test{1}/
198+
special/{}/
194199
subdir_one/
195200
subdir_two/
196201
]

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

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

458-
left_brace_index = pattern.index('{')
458+
left_brace_index = pattern.index(/(?<!\\){/)
459459
if left_brace_index
460460
patterns = compile(pattern, left_brace_index, flags)
461461

0 commit comments

Comments
 (0)