Skip to content

Commit f6d16c8

Browse files
authored
[pub_formats] Fix regex for executable keys (#2469)
1 parent 08987ba commit f6d16c8

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

pkgs/pub_formats/doc/schema/pubspec.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"type": "object",
4242
"additionalProperties": false,
4343
"patternProperties": {
44-
"^[a-zA-Z_]\\w*$": {
44+
"^[a-zA-Z_]\\w*(-[a-zA-Z_]\\w*)*$": {
4545
"oneOf": [
4646
{
4747
"description": "If null, the main file is lib/<package_name>.dart.",

pkgs/pub_formats/lib/src/pubspec_syntax.g.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,9 @@ class PubspecYamlFileSyntax extends JsonObjectSyntax {
503503
return environment.validate();
504504
}
505505

506-
static final _executablesKeyPattern = RegExp(r'^[a-zA-Z_]\w*$');
506+
static final _executablesKeyPattern = RegExp(
507+
r'^[a-zA-Z_]\w*(-[a-zA-Z_]\w*)*$',
508+
);
507509

508510
static final _executablesValuePattern = RegExp(r'^[^/\\]*$');
509511

pkgs/pub_formats/test/pubspec_test.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ void main() {
5959
expect(someSdkDependency2.sdk, equals('flutter'));
6060
expect(syntax.dependencyOverrides, isNull);
6161
expect(syntax.executables, isNotNull);
62-
expect(syntax.executables, equals({'slidy': 'main', 'fvm': null}));
62+
expect(
63+
syntax.executables,
64+
equals({'slidy': 'main', 'fvm': null, 'dart-apitool': 'main'}),
65+
);
6366
expect(syntax.publishTo, equals('none'));
6467
expect(syntax.documentation, isNull);
6568
expect(syntax.issueTracker, isNull);
@@ -103,7 +106,7 @@ void main() {
103106
expect(
104107
syntaxError2.validate(),
105108
equals([
106-
"Unexpected key 'invalid executable name' in 'executables'. Expected a key satisfying ^[a-zA-Z_]\\w*\$.",
109+
"Unexpected key 'invalid executable name' in 'executables'. Expected a key satisfying ^[a-zA-Z_]\\w*(-[a-zA-Z_]\\w*)*\$.",
107110
]),
108111
);
109112
expect(() => syntaxError2.executables, throwsFormatException);

pkgs/pub_formats/test_data/pubspec_1.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dev_dependencies:
3838
executables:
3939
slidy: main
4040
fvm:
41+
dart-apitool: main
4142

4243
# Hook user-defines are specified in the pub workspace.
4344
hooks:

0 commit comments

Comments
 (0)