Skip to content

Commit 0374905

Browse files
authored
Always escape when writing pubspec.yaml's 'description' field. (#130096)
Closes flutter/flutter#80013. **Before**: ``` $ flutter create test1 --description "a: b" Creating project test1... Error detected in pubspec.yaml: Error on line 2, column 15: Mapping values are not allowed here. Did you miss a colon earlier? � 2 � description: a: b � ^ � Please correct the pubspec.yaml file at /Users/matan/Developer/scratch/test1/pubspec.yaml ``` **After**: ``` $ flutter create test1 --description "a: b" Creating project test1... Resolving dependencies in test1... Got dependencies in test1. Wrote 129 files. All done! You can find general documentation for Flutter at: https://docs.flutter.dev/ Detailed API documentation is available at: https://api.flutter.dev/ If you prefer video documentation, consider: https://www.youtube.com/c/flutterdev In order to run your application, type: $ cd test1 $ flutter run Your application code is in test1/lib/main.dart. ``` --- It's worth noting that this _always_ escapes a non-empty project description, which means that descriptions that were not previously wrapped in `"`s' will be. I'm not sure how worth it is to do a _conditional_ escape (i.e. only escape if not escaping would cause a problem), but willing to change. Side-note: I had no idea where to list this test in the (very large) `create_test.dart`, so I did my best :)
1 parent 7fc4990 commit 0374905

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

packages/flutter_tools/lib/src/commands/create_base.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ abstract class CreateBase extends FlutterCommand {
389389
'macosIdentifier': appleIdentifier,
390390
'linuxIdentifier': linuxIdentifier,
391391
'windowsIdentifier': windowsIdentifier,
392-
'description': projectDescription,
392+
'description': projectDescription != null ? escapeYamlString(projectDescription) : null,
393393
'dartSdk': '$flutterRoot/bin/cache/dart-sdk',
394394
'androidMinApiLevel': android_common.minApiLevel,
395395
'androidSdkVersion': kAndroidSdkMinVersion,

packages/flutter_tools/test/commands.shard/permeable/create_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,6 +3266,24 @@ void main() {
32663266
),
32673267
});
32683268

3269+
testUsingContext('should escape ":" in project description', () async {
3270+
await _createProject(
3271+
projectDir,
3272+
<String>[
3273+
'--no-pub',
3274+
'--description',
3275+
'a: b',
3276+
],
3277+
<String>[
3278+
'pubspec.yaml',
3279+
],
3280+
);
3281+
3282+
final String rawPubspec = await projectDir.childFile('pubspec.yaml').readAsString();
3283+
final Pubspec pubspec = Pubspec.parse(rawPubspec);
3284+
expect(pubspec.description, 'a: b');
3285+
});
3286+
32693287
testUsingContext('create an FFI plugin with ios, then add macos', () async {
32703288
Cache.flutterRoot = '../..';
32713289

0 commit comments

Comments
 (0)