Skip to content

Commit

Permalink
Don't html-escape in the plugin registrant templates. (flutter#43448)
Browse files Browse the repository at this point in the history
* Don't html-escape in the plugin registrant templates.

Fixes flutter#43382

* Add test
  • Loading branch information
Harry Terkelsen authored and Inconnu08 committed Nov 5, 2019
1 parent 2b4c41c commit 5487070
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
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 {}

0 comments on commit 5487070

Please sign in to comment.