Unverified Commit 3581b3ae authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Make font manifest descriptors consistent with the paths used for font assets (#22375)

The asset subsystem uses URIs to represent asset locations.  The font manifest
should also use URI-encoded paths instead of unencoded paths taken directly
from the manifest YAML.

Fixes https://github.com/flutter/flutter/issues/19452
parent f1967485
...@@ -149,6 +149,10 @@ class FlutterManifest { ...@@ -149,6 +149,10 @@ class FlutterManifest {
} }
List<Map<String, dynamic>> get fontsDescriptor { List<Map<String, dynamic>> get fontsDescriptor {
return fonts.map((Font font) => font.descriptor).toList();
}
List<Map<String, dynamic>> get _rawFontsDescriptor {
final List<dynamic> fontList = _flutterDescriptor['fonts']; final List<dynamic> fontList = _flutterDescriptor['fonts'];
return fontList == null return fontList == null
? const <Map<String, dynamic>>[] ? const <Map<String, dynamic>>[]
...@@ -179,7 +183,7 @@ class FlutterManifest { ...@@ -179,7 +183,7 @@ class FlutterManifest {
return <Font>[]; return <Font>[];
final List<Font> fonts = <Font>[]; final List<Font> fonts = <Font>[];
for (Map<String, dynamic> fontFamily in fontsDescriptor) { for (Map<String, dynamic> fontFamily in _rawFontsDescriptor) {
final List<dynamic> fontFiles = fontFamily['fonts']; final List<dynamic> fontFiles = fontFamily['fonts'];
final String familyName = fontFamily['family']; final String familyName = fontFamily['family'];
if (familyName == null) { if (familyName == null) {
......
...@@ -89,8 +89,8 @@ $fontsSection ...@@ -89,8 +89,8 @@ $fontsSection
} }
expect( expect(
utf8.decode(await bundle.entries['FontManifest.json'].contentsAsBytes()), json.decode(utf8.decode(await bundle.entries['FontManifest.json'].contentsAsBytes())),
expectedAssetManifest, json.decode(expectedAssetManifest),
); );
} }
......
...@@ -92,13 +92,13 @@ flutter: ...@@ -92,13 +92,13 @@ flutter:
- asset: a/bar - asset: a/bar
'''; ''';
final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest); final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest);
final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types
expect(flutterManifest.fontsDescriptor.toString(), '[{fonts: [{asset: a/bar}], family: foo}]'); expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor);
final List<Font> fonts = flutterManifest.fonts; final List<Font> fonts = flutterManifest.fonts;
expect(fonts.length, 1); expect(fonts.length, 1);
final Font font = fonts[0]; final Font font = fonts[0];
const String fontDescriptor = '{family: foo, fonts: [{asset: a/bar}]}'; final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}]}; // ignore: always_specify_types
expect(font.descriptor.toString(), fontDescriptor); expect(font.descriptor, fooFontDescriptor);
expect(font.familyName, 'foo'); expect(font.familyName, 'foo');
final List<FontAsset> assets = font.fontAssets; final List<FontAsset> assets = font.fontAssets;
expect(assets.length, 1); expect(assets.length, 1);
...@@ -124,14 +124,13 @@ flutter: ...@@ -124,14 +124,13 @@ flutter:
weight: 400 weight: 400
'''; ''';
final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest); final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest);
final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types
const String expectedFontsDescriptor = '[{fonts: [{asset: a/bar}, {weight: 400, asset: a/bar}], family: foo}]'; expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor);
expect(flutterManifest.fontsDescriptor.toString(), expectedFontsDescriptor);
final List<Font> fonts = flutterManifest.fonts; final List<Font> fonts = flutterManifest.fonts;
expect(fonts.length, 1); expect(fonts.length, 1);
final Font font = fonts[0]; final Font font = fonts[0];
const String fontDescriptor = '{family: foo, fonts: [{asset: a/bar}, {weight: 400, asset: a/bar}]}'; final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'asset': 'a/bar'}]}; // ignore: always_specify_types
expect(font.descriptor.toString(), fontDescriptor); expect(font.descriptor, fooFontDescriptor);
expect(font.familyName, 'foo'); expect(font.familyName, 'foo');
final List<FontAsset> assets = font.fontAssets; final List<FontAsset> assets = font.fontAssets;
expect(assets.length, 2); expect(assets.length, 2);
...@@ -162,14 +161,14 @@ flutter: ...@@ -162,14 +161,14 @@ flutter:
style: italic style: italic
'''; ''';
final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest); final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest);
final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types
const String expectedFontsDescriptor = '[{fonts: [{asset: a/bar}, {style: italic, weight: 400, asset: a/bar}], family: foo}]'; expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor);
expect(flutterManifest.fontsDescriptor.toString(), expectedFontsDescriptor);
final List<Font> fonts = flutterManifest.fonts; final List<Font> fonts = flutterManifest.fonts;
expect(fonts.length, 1); expect(fonts.length, 1);
final Font font = fonts[0]; final Font font = fonts[0];
const String fontDescriptor = '{family: foo, fonts: [{asset: a/bar}, {weight: 400, style: italic, asset: a/bar}]}'; final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types
expect(font.descriptor.toString(), fontDescriptor); expect(font.descriptor, fooFontDescriptor);
expect(font.familyName, 'foo'); expect(font.familyName, 'foo');
final List<FontAsset> assets = font.fontAssets; final List<FontAsset> assets = font.fontAssets;
expect(assets.length, 2); expect(assets.length, 2);
...@@ -206,16 +205,17 @@ flutter: ...@@ -206,16 +205,17 @@ flutter:
style: italic style: italic
'''; ''';
final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest); final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest);
final dynamic expectedFontsDescriptor = <dynamic>[
const String expectedFontsDescriptor = '[{fonts: [{asset: a/bar}, {style: italic, weight: 400, asset: a/bar}], family: foo},' {'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}, // ignore: always_specify_types
' {fonts: [{asset: a/baz}, {style: italic, weight: 400, asset: a/baz}], family: bar}]'; {'fonts': [{'asset': 'a/baz'}, {'style': 'italic', 'weight': 400, 'asset': 'a/baz'}], 'family': 'bar'}, // ignore: always_specify_types
expect(flutterManifest.fontsDescriptor.toString(), expectedFontsDescriptor); ];
expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor);
final List<Font> fonts = flutterManifest.fonts; final List<Font> fonts = flutterManifest.fonts;
expect(fonts.length, 2); expect(fonts.length, 2);
final Font fooFont = fonts[0]; final Font fooFont = fonts[0];
const String barFontDescriptor = '{family: foo, fonts: [{asset: a/bar}, {weight: 400, style: italic, asset: a/bar}]}'; final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types
expect(fooFont.descriptor.toString(), barFontDescriptor); expect(fooFont.descriptor, fooFontDescriptor);
expect(fooFont.familyName, 'foo'); expect(fooFont.familyName, 'foo');
final List<FontAsset> fooAassets = fooFont.fontAssets; final List<FontAsset> fooAassets = fooFont.fontAssets;
expect(fooAassets.length, 2); expect(fooAassets.length, 2);
...@@ -229,7 +229,7 @@ flutter: ...@@ -229,7 +229,7 @@ flutter:
expect(fooFontAsset1.style, 'italic'); expect(fooFontAsset1.style, 'italic');
final Font barFont = fonts[1]; final Font barFont = fonts[1];
const String fontDescriptor = '{family: bar, fonts: [{asset: a/baz}, {weight: 400, style: italic, asset: a/baz}]}'; const String fontDescriptor = '{family: bar, fonts: [{asset: a/baz}, {weight: 400, style: italic, asset: a/baz}]}'; // ignore: always_specify_types
expect(barFont.descriptor.toString(), fontDescriptor); expect(barFont.descriptor.toString(), fontDescriptor);
expect(barFont.familyName, 'bar'); expect(barFont.familyName, 'bar');
final List<FontAsset> barAssets = barFont.fontAssets; final List<FontAsset> barAssets = barFont.fontAssets;
...@@ -267,15 +267,13 @@ flutter: ...@@ -267,15 +267,13 @@ flutter:
'''; ''';
final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest); final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest);
final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types
const String expectedFontsDescriptor = '[{fonts: [{asset: a/bar}, {style: italic, weight: 400, asset: a/bar}], family: foo},' expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor);
' {fonts: [{asset: a/baz}, {style: italic, weight: 400, asset: a/baz}]}]';
expect(flutterManifest.fontsDescriptor.toString(), expectedFontsDescriptor);
final List<Font> fonts = flutterManifest.fonts; final List<Font> fonts = flutterManifest.fonts;
expect(fonts.length, 1); expect(fonts.length, 1);
final Font fooFont = fonts[0]; final Font fooFont = fonts[0];
const String barFontDescriptor = '{family: foo, fonts: [{asset: a/bar}, {weight: 400, style: italic, asset: a/bar}]}'; final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types
expect(fooFont.descriptor.toString(), barFontDescriptor); expect(fooFont.descriptor, fooFontDescriptor);
expect(fooFont.familyName, 'foo'); expect(fooFont.familyName, 'foo');
final List<FontAsset> fooAassets = fooFont.fontAssets; final List<FontAsset> fooAassets = fooFont.fontAssets;
expect(fooAassets.length, 2); expect(fooAassets.length, 2);
...@@ -307,15 +305,13 @@ flutter: ...@@ -307,15 +305,13 @@ flutter:
- family: bar - family: bar
'''; ''';
final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest); final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest);
final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types
const String expectedFontsDescriptor = '[{fonts: [{asset: a/bar}, {style: italic, weight: 400, asset: a/bar}], family: foo},' expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor);
' {family: bar}]';
expect(flutterManifest.fontsDescriptor.toString(), expectedFontsDescriptor);
final List<Font> fonts = flutterManifest.fonts; final List<Font> fonts = flutterManifest.fonts;
expect(fonts.length, 1); expect(fonts.length, 1);
final Font fooFont = fonts[0]; final Font fooFont = fonts[0];
const String barFontDescriptor = '{family: foo, fonts: [{asset: a/bar}, {weight: 400, style: italic, asset: a/bar}]}'; final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types
expect(fooFont.descriptor.toString(), barFontDescriptor); expect(fooFont.descriptor, fooFontDescriptor);
expect(fooFont.familyName, 'foo'); expect(fooFont.familyName, 'foo');
final List<FontAsset> fooAassets = fooFont.fontAssets; final List<FontAsset> fooAassets = fooFont.fontAssets;
expect(fooAassets.length, 2); expect(fooAassets.length, 2);
...@@ -344,8 +340,7 @@ flutter: ...@@ -344,8 +340,7 @@ flutter:
'''; ''';
final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest); final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest);
const String expectedFontsDescriptor = '[{fonts: [{weight: 400}], family: foo}]'; expect(flutterManifest.fontsDescriptor, <dynamic>[]);
expect(flutterManifest.fontsDescriptor.toString(), expectedFontsDescriptor);
final List<Font> fonts = flutterManifest.fonts; final List<Font> fonts = flutterManifest.fonts;
expect(fonts.length, 0); expect(fonts.length, 0);
}); });
......
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