Unverified Commit 03664d0a authored by Navaron Bracke's avatar Navaron Bracke Committed by GitHub

Fix description in index.html / manifest.json getting double quoted (#131842)

This PR adjusts the quoting of the project description not not apply twice in the index.html / manifest.json of web builds.

*List which issues are fixed by this PR. You must list at least one issue.*
Fixes https://github.com/flutter/flutter/issues/131834

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
parent a1e3b3da
......@@ -389,7 +389,7 @@ abstract class CreateBase extends FlutterCommand {
'macosIdentifier': appleIdentifier,
'linuxIdentifier': linuxIdentifier,
'windowsIdentifier': windowsIdentifier,
'description': projectDescription != null ? escapeYamlString(projectDescription) : null,
'description': projectDescription,
'dartSdk': '$flutterRoot/bin/cache/dart-sdk',
'androidMinApiLevel': android_common.minApiLevel,
'androidSdkVersion': kAndroidSdkMinVersion,
......
......@@ -361,7 +361,13 @@ class Template {
context['androidIdentifier'] = _escapeKotlinKeywords(androidIdentifier);
}
final String renderedContents = _templateRenderer.renderString(templateContents, context);
// Use a copy of the context,
// since the original is used in rendering other templates.
final Map<String, Object?> localContext = finalDestinationFile.path.endsWith('.yaml')
? _createEscapedContextCopy(context)
: context;
final String renderedContents = _templateRenderer.renderString(templateContents, localContext);
finalDestinationFile.writeAsStringSync(renderedContents);
......@@ -377,6 +383,21 @@ class Template {
}
}
/// Create a copy of the given [context], escaping its values when necessary.
///
/// Returns the copied context.
Map<String, Object?> _createEscapedContextCopy(Map<String, Object?> context) {
final Map<String, Object?> localContext = Map<String, Object?>.of(context);
final String? description = localContext['description'] as String?;
if (description != null && description.isNotEmpty) {
localContext['description'] = escapeYamlString(description);
}
return localContext;
}
String _escapeKotlinKeywords(String androidIdentifier) {
final List<String> segments = androidIdentifier.split('.');
final List<String> correctedSegments = segments.map(
......
......@@ -3384,6 +3384,32 @@ void main() {
FeatureFlags: () => TestFeatureFlags(),
Logger: () => logger,
});
testUsingContext('Does not double quote description in index.html on web', () async {
await _createProject(
projectDir,
<String>['--no-pub', '--platforms=web'],
<String>['pubspec.yaml', 'web/index.html'],
);
final String rawIndexHtml = await projectDir.childDirectory('web').childFile('index.html').readAsString();
const String expectedDescription = '<meta name="description" content="A new Flutter project.">';
expect(rawIndexHtml.contains(expectedDescription), isTrue);
});
testUsingContext('Does not double quote description in manifest.json on web', () async {
await _createProject(
projectDir,
<String>['--no-pub', '--platforms=web'],
<String>['pubspec.yaml', 'web/manifest.json'],
);
final String rawManifestJson = await projectDir.childDirectory('web').childFile('manifest.json').readAsString();
const String expectedDescription = '"description": "A new Flutter project."';
expect(rawManifestJson.contains(expectedDescription), isTrue);
});
}
Future<void> _createProject(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment