Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
52ddc9d1
Unverified
Commit
52ddc9d1
authored
May 18, 2022
by
Jenn Magder
Committed by
GitHub
May 18, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle null values during yaml metadata parsing validation (#104022)
parent
b8b3b09a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
19 deletions
+28
-19
flutter_project_metadata.dart
packages/flutter_tools/lib/src/flutter_project_metadata.dart
+13
-19
flutter_project_metadata_test.dart
...ols/test/general.shard/flutter_project_metadata_test.dart
+15
-0
No files found.
packages/flutter_tools/lib/src/flutter_project_metadata.dart
View file @
52ddc9d1
...
...
@@ -51,11 +51,7 @@ FlutterProjectType? stringToProjectType(String value) {
}
/// Verifies the expected yaml keys are present in the file.
bool
_validateMetadataMap
(
Object
?
yamlRoot
,
Map
<
String
,
Type
>
validations
,
Logger
logger
)
{
if
(
yamlRoot
!=
null
&&
yamlRoot
is
!
YamlMap
)
{
return
false
;
}
final
YamlMap
map
=
yamlRoot
!
as
YamlMap
;
bool
_validateMetadataMap
(
YamlMap
map
,
Map
<
String
,
Type
>
validations
,
Logger
logger
)
{
bool
isValid
=
true
;
for
(
final
MapEntry
<
String
,
Object
>
entry
in
validations
.
entries
)
{
if
(!
map
.
keys
.
contains
(
entry
.
key
))
{
...
...
@@ -63,9 +59,10 @@ FlutterProjectType? stringToProjectType(String value) {
logger
.
printTrace
(
'The key `
${entry.key}
` was not found'
);
break
;
}
if
(
map
[
entry
.
key
]
!=
null
&&
(
map
[
entry
.
key
]
as
Object
).
runtimeType
!=
entry
.
value
)
{
final
Object
?
metadataValue
=
map
[
entry
.
key
];
if
(
metadataValue
.
runtimeType
!=
entry
.
value
)
{
isValid
=
false
;
logger
.
printTrace
(
'The value of key `
${entry.key}
` in .metadata was expected to be
${entry.value}
but was
${
(map[entry.key] as Object)
.runtimeType}
'
);
logger
.
printTrace
(
'The value of key `
${entry.key}
` in .metadata was expected to be
${entry.value}
but was
${
metadataValue
.runtimeType}
'
);
break
;
}
}
...
...
@@ -89,28 +86,26 @@ class FlutterProjectMetadata {
}
on
YamlException
{
// Handled in _validate below.
}
if
(
yamlRoot
==
null
||
yamlRoot
is
!
YamlMap
)
{
if
(
yamlRoot
is
!
YamlMap
)
{
_logger
.
printTrace
(
'.metadata file at
${_metadataFile.path}
was empty or malformed.'
);
return
;
}
final
YamlMap
map
=
yamlRoot
;
if
(
_validateMetadataMap
(
yamlRoot
,
<
String
,
Type
>{
'version'
:
YamlMap
},
_logger
))
{
final
Object
?
versionYaml
=
map
[
'version'
];
if
(
_validateMetadataMap
(
versionYaml
,
<
String
,
Type
>{
final
Object
?
versionYaml
Map
=
yamlRoot
[
'version'
];
if
(
versionYamlMap
is
YamlMap
&&
_validateMetadataMap
(
versionYamlMap
,
<
String
,
Type
>{
'revision'
:
String
,
'channel'
:
String
,
},
_logger
))
{
final
YamlMap
versionYamlMap
=
versionYaml
!
as
YamlMap
;
_versionRevision
=
versionYamlMap
[
'revision'
]
as
String
?;
_versionChannel
=
versionYamlMap
[
'channel'
]
as
String
?;
}
}
if
(
_validateMetadataMap
(
yamlRoot
,
<
String
,
Type
>{
'project_type'
:
String
},
_logger
))
{
_projectType
=
stringToProjectType
(
map
[
'project_type'
]
as
String
);
_projectType
=
stringToProjectType
(
yamlRoot
[
'project_type'
]
as
String
);
}
final
Object
?
migrationYaml
=
map
[
'migration'
];
if
(
migrationYaml
!=
null
&&
migrationYaml
is
YamlMap
)
{
migrateConfig
.
parseYaml
(
m
ap
[
'migration'
]
as
YamlMap
,
_logger
);
final
Object
?
migrationYaml
=
yamlRoot
[
'migration'
];
if
(
migrationYaml
is
YamlMap
)
{
migrateConfig
.
parseYaml
(
m
igrationYaml
,
_logger
);
}
}
...
...
@@ -289,13 +284,12 @@ migration:
final
Object
?
platformsYaml
=
map
[
'platforms'
];
if
(
_validateMetadataMap
(
map
,
<
String
,
Type
>{
'platforms'
:
YamlList
},
logger
))
{
if
(
platformsYaml
is
YamlList
&&
platformsYaml
.
isNotEmpty
)
{
for
(
final
Object
?
platform
in
platformsYaml
)
{
if
(
_validateMetadataMap
(
platform
,
<
String
,
Type
>{
for
(
final
YamlMap
platformYamlMap
in
platformsYaml
.
whereType
<
YamlMap
>()
)
{
if
(
_validateMetadataMap
(
platform
YamlMap
,
<
String
,
Type
>{
'platform'
:
String
,
'create_revision'
:
String
,
'base_revision'
:
String
,
},
logger
))
{
final
YamlMap
platformYamlMap
=
platform
!
as
YamlMap
;
final
SupportedPlatform
platformString
=
SupportedPlatform
.
values
.
firstWhere
(
(
SupportedPlatform
val
)
=>
val
.
toString
()
==
'SupportedPlatform.
${platformYamlMap['platform'] as String}
'
);
...
...
packages/flutter_tools/test/general.shard/flutter_project_metadata_test.dart
View file @
52ddc9d1
...
...
@@ -50,6 +50,21 @@ void main() {
expect
(
logger
.
traceText
,
contains
(
'.metadata file at .metadata was empty or malformed.'
));
});
testWithoutContext
(
'projectType is populated when version is null'
,
()
{
metadataFile
..
createSync
()
..
writeAsStringSync
(
'''
version:
project_type: plugin
'''
);
final
FlutterProjectMetadata
projectMetadata
=
FlutterProjectMetadata
(
metadataFile
,
logger
);
expect
(
projectMetadata
.
projectType
,
FlutterProjectType
.
plugin
);
expect
(
projectMetadata
.
versionChannel
,
isNull
);
expect
(
projectMetadata
.
versionRevision
,
isNull
);
expect
(
logger
.
traceText
,
contains
(
'The value of key `version` in .metadata was expected to be YamlMap but was Null'
));
});
testWithoutContext
(
'projectType is populated when version is malformed'
,
()
{
metadataFile
..
createSync
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment