-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fix description in index.html / manifest.json getting double quoted #131842
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
Fix description in index.html / manifest.json getting double quoted #131842
Conversation
|
This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
packages/flutter_tools/test/commands.shard/permeable/create_test.dart
Outdated
Show resolved
Hide resolved
andrewkolos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there's a better way to approach the problem.
Instead of undoing the YAML-string-escaping when writing to a non-YAML file, should we just delay YAML-escaping until we are writing to YAML files?
It seems odd to YAML-escape string items when creating context, when these items might not be used for only YAML files.
I will bring this up during weekly tool PR review (Aug 10).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have this comment explain where the extra quotes came from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to do that, then a future reader will also see why we had this bug in the first place :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the 'extra' quotes have been eliminated from createTemplateContext(), I've adjusted the comment to mention why we add quotes instead.
packages/flutter_tools/test/commands.shard/permeable/create_test.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for myself when doing my next review pass:
Is it safe to modify context here? Will this result in bugs if we change the rendering order of the template files? Instead of writing to context['description'], maybe we should just make a local copy of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we'd have to make sure that the template renderer gets the local when calling renderString(), which might not be as flexible if other things need to get passed down in the future.
I think your idea of delaying the YAML escaping, until we have a YAML file to create makes more sense here.
Then it is up to the template renderer to decide when to escape what.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made a local copy of the context when writing to the pubspec.
|
@andrewkolos I had a second look at how the template is rendered. So we pass things to Apparently it has a Wouldn't it be better if it did the same for yaml? Edit: Since that is a third-party dependency, I decided to go ahead and adhere to your original feedback. We can always revisit if needed. |
andrewkolos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, sorry for being absent. I was out of action towards the end of last week. I requested one change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the second condition redundant with the first? Also, consider making the leading comment more concise.
| // YAML files require that their input is properly escaped with quotes. | |
| // Adjust the current context to escape the needed inputs, before writing to the template. | |
| if (finalDestinationFile.path.endsWith('.yaml')) { | |
| if (finalDestinationFile.path.endsWith('pubspec.yaml')) { | |
| // Grab a copy of the context, since it is used to render other templates as well. | |
| localContext = Map<String, Object?>.of(localContext); | |
| final String? description = localContext['description'] as String?; | |
| if (description != null && description.isNotEmpty) { | |
| localContext['description'] = escapeYamlString(description); | |
| } | |
| } | |
| } | |
| // Ensure inputs are escaped when necessary. | |
| if (finalDestinationFile.path.endsWith('.yaml')) { | |
| // Use copy of the context, since the original is used in rendering other templates. | |
| localContext = Map<String, Object?>.of(localContext); | |
| final String? description = localContext['description'] as String?; | |
| if (description != null && description.isNotEmpty) { | |
| localContext['description'] = escapeYamlString(description); | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries :)
Yeah, I was a bit conservative about "what if we need to handle other YAML files in the future", but that doesn't happen often.
Adjusted the condition and updated the comment.
andrewkolos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
3438c6b to
776a44e
Compare
|
Rebased on ToT to kick off the Google Testing check again |
|
@christopherfujino Are you able to take a look at this? |
| Map<String, Object?> localContext = context; | ||
|
|
||
| // Ensure inputs are escaped when necessary. | ||
| if (finalDestinationFile.path.endsWith('.yaml')) { | ||
| // Use a copy of the context, | ||
| // since the original is used in rendering other templates. | ||
| localContext = Map<String, Object?>.of(localContext); | ||
|
|
||
| final String? description = localContext['description'] as String?; | ||
|
|
||
| if (description != null && description.isNotEmpty) { | ||
| localContext['description'] = escapeYamlString(description); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little worried that we're conditionally mutating the localContext variable, and this behavior may be obscured and forgotten in the future. Instead, can you pull the escaping logic into a helper function with a dartdoc, so it's more clear when and why we would be escaping, and with which copy?
| Map<String, Object?> localContext = context; | |
| // Ensure inputs are escaped when necessary. | |
| if (finalDestinationFile.path.endsWith('.yaml')) { | |
| // Use a copy of the context, | |
| // since the original is used in rendering other templates. | |
| localContext = Map<String, Object?>.of(localContext); | |
| final String? description = localContext['description'] as String?; | |
| if (description != null && description.isNotEmpty) { | |
| localContext['description'] = escapeYamlString(description); | |
| } | |
| } | |
| final Map<String, Object?> localContext = finalDestinationFile.path.endsWith('.yaml') | |
| ? _createEscapedContextCopy(context) | |
| : context; |
And then the inner block moved into Map<String, Object?> _createEscapedContextCopy(Map<String, Object?> oldContext)
christopherfujino
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks for this fix!
|
Thanks for the fix @navaronbracke ! |
This PR adjusts the quoting of the project description not not apply twice in the index.html / manifest.json of web builds.
List which issues are fixed by this PR. You must list at least one issue.
Fixes #131834
If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.