Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't html-escape in the plugin registrant templates. #43448

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/plugins.dart
Expand Up @@ -20,7 +20,7 @@ import 'project.dart';

void _renderTemplateToFile(String template, dynamic context, String filePath) {
final String renderedTemplate =
mustache.Template(template).renderString(context);
mustache.Template(template, htmlEscapeValues: false).renderString(context);
final File file = fs.file(filePath);
file.createSync(recursive: true);
file.writeAsStringSync(renderedTemplate);
Expand Down
54 changes: 54 additions & 0 deletions packages/flutter_tools/test/general.shard/plugins_test.dart
Expand Up @@ -21,6 +21,7 @@ void main() {
MockIosProject iosProject;
MockMacOSProject macosProject;
MockAndroidProject androidProject;
MockWebProject webProject;
File packagesFile;
Directory dummyPackageDirectory;

Expand All @@ -44,6 +45,10 @@ void main() {
when(flutterProject.android).thenReturn(androidProject);
when(androidProject.pluginRegistrantHost).thenReturn(flutterProject.directory.childDirectory('android').childDirectory('app'));
when(androidProject.hostAppGradleRoot).thenReturn(flutterProject.directory.childDirectory('android'));
webProject = MockWebProject();
when(flutterProject.web).thenReturn(webProject);
when(webProject.libDirectory).thenReturn(flutterProject.directory.childDirectory('lib'));
when(webProject.existsSync()).thenReturn(true);

// Set up a simple .packages file for all the tests to use, pointing to one package.
dummyPackageDirectory = fs.directory('/pubcache/apackage/lib/');
Expand Down Expand Up @@ -392,6 +397,54 @@ plugin3:${pluginUsingOldEmbeddingDir.childDirectory('lib').uri.toString()}
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => featureFlags,
});

testUsingContext('Registrant for web doesn\'t escape slashes in imports', () async {
when(flutterProject.isModule).thenReturn(true);
when(featureFlags.isWebEnabled).thenReturn(true);

// injectPlugins will crash if there is no AndroidManifest
final File androidManifest = flutterProject.directory
.childDirectory('android')
.childFile('AndroidManifest.xml')
..createSync(recursive: true)
..writeAsStringSync(kAndroidManifestUsingOldEmbedding);
when(androidProject.appManifestFile).thenReturn(androidManifest);

final Directory webPluginWithNestedFile =
fs.systemTempDirectory.createTempSync('web_plugin_with_nested');
webPluginWithNestedFile.childFile('pubspec.yaml').writeAsStringSync('''
flutter:
plugin:
platforms:
web:
pluginClass: WebPlugin
fileName: src/web_plugin.dart
''');
webPluginWithNestedFile
.childDirectory('lib')
.childDirectory('src')
.childFile('web_plugin.dart')
..createSync(recursive: true);

flutterProject.directory
.childFile('.packages')
.writeAsStringSync('''
web_plugin_with_nested:${webPluginWithNestedFile.childDirectory('lib').uri.toString()}
''');

await injectPlugins(flutterProject);

final File registrant = flutterProject.directory
.childDirectory('lib')
.childFile('generated_plugin_registrant.dart');

expect(registrant.existsSync(), isTrue);
expect(registrant.readAsStringSync(), contains("import 'package:web_plugin_with_nested/src/web_plugin.dart';"));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => featureFlags,
});
});
}

Expand All @@ -401,3 +454,4 @@ class MockFlutterProject extends Mock implements FlutterProject {}
class MockIosProject extends Mock implements IosProject {}
class MockMacOSProject extends Mock implements MacOSProject {}
class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterpreter {}
class MockWebProject extends Mock implements WebProject {}