Skip to content

Commit f6b8440

Browse files
Support path with parenthesis (#703)
- Escape glob characters in file paths before performing globs
1 parent 4cff945 commit f6b8440

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

source_gen/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Document deduplication behavior for the output of
44
`GeneratorForAnnotation.generateForAnnotatedElement`.
5+
- Support all the glob quotes.
56

67
## 1.5.0
78

source_gen/lib/builder.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ class CombiningBuilder implements Builder {
8282
@override
8383
Future<void> build(BuildStep buildStep) async {
8484
// Pattern used for `findAssets`, which must be glob-compatible
85-
final pattern = buildStep.inputId.changeExtension('.*$_partFiles').path;
85+
final assetPath = buildStep.inputId.path;
86+
final pattern = '${p.withoutExtension(Glob.quote(assetPath))}.*$_partFiles';
8687

8788
final inputBaseName =
8889
p.basenameWithoutExtension(buildStep.inputId.pathSegments.last);

source_gen/test/builder_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,24 @@ foo generated content
799799
);
800800
});
801801
});
802+
803+
test('supports the path with the glob quotes', () async {
804+
await testBuilder(
805+
const CombiningBuilder(),
806+
{
807+
'$_pkgName|lib/[a]/(b)/{c}/*d/-e/f.dart':
808+
'library f; part "f.g.dart";',
809+
'$_pkgName|lib/[a]/(b)/{c}/*d/-e/f.foo.g.part':
810+
'some generated content',
811+
},
812+
generateFor: {'$_pkgName|lib/[a]/(b)/{c}/*d/-e/f.dart'},
813+
outputs: {
814+
'$_pkgName|lib/[a]/(b)/{c}/*d/-e/f.g.dart': decodedMatches(
815+
startsWith('// GENERATED CODE - DO NOT MODIFY BY HAND'),
816+
),
817+
},
818+
);
819+
});
802820
});
803821

804822
test('can skip formatting with a trivial lambda', () async {

0 commit comments

Comments
 (0)