Unverified Commit 24bfbeb2 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Handle whitespace in entry values in the AAPT badging parser (#16245)

Fixes https://github.com/flutter/flutter/issues/16200
parent 3aebc070
......@@ -3,8 +3,9 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:collection';
import 'package:meta/meta.dart' show required;
import 'package:meta/meta.dart';
import 'package:xml/xml.dart' as xml;
import 'android/android_sdk.dart';
......@@ -321,6 +322,8 @@ class ApkManifestData {
// launchable-activity: name='io.flutter.app.FlutterActivity' label='' icon=''
final Map<String, Map<String, String>> map = <String, Map<String, String>>{};
final RegExp keyValueRegex = new RegExp(r"(\S+?)='(.*?)'");
for (String line in data.split('\n')) {
final int index = line.indexOf(':');
if (index != -1) {
......@@ -330,16 +333,8 @@ class ApkManifestData {
final Map<String, String> entries = <String, String>{};
map[name] = entries;
for (String entry in line.split(' ')) {
entry = entry.trim();
if (entry.isNotEmpty && entry.contains('=')) {
final int split = entry.indexOf('=');
final String key = entry.substring(0, split);
String value = entry.substring(split + 1);
if (value.startsWith("'") && value.endsWith("'"))
value = value.substring(1, value.length - 1);
entries[key] = value;
}
for (Match m in keyValueRegex.allMatches(line)) {
entries[m.group(1)] = m.group(2);
}
}
}
......@@ -349,6 +344,10 @@ class ApkManifestData {
final Map<String, Map<String, String>> _data;
@visibleForTesting
Map<String, Map<String, String>> get data =>
new UnmodifiableMapView<String, Map<String, String>>(_data);
String get packageName => _data['package'] == null ? null : _data['package']['name'];
String get launchableActivityName {
......
......@@ -14,6 +14,7 @@ void main() {
expect(data, isNotNull);
expect(data.packageName, 'io.flutter.gallery');
expect(data.launchableActivityName, 'io.flutter.app.FlutterActivity');
expect(data.data['application']['label'], 'Flutter Gallery');
});
});
......
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