Skip to content

Conversation

@navaronbracke
Copy link
Contributor

@navaronbracke navaronbracke commented Aug 3, 2023

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

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Aug 3, 2023
@navaronbracke navaronbracke marked this pull request as draft August 3, 2023 12:59
@flutter-dashboard
Copy link

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 package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@navaronbracke navaronbracke marked this pull request as ready for review August 3, 2023 13:19
@navaronbracke navaronbracke changed the title Fix description in index.html getting double quoted Fix description in index.html / manifest.json getting double quoted Aug 3, 2023
@andrewkolos andrewkolos self-requested a review August 3, 2023 20:30
Copy link
Contributor

@andrewkolos andrewkolos left a 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).

Comment on lines 334 to 335
Copy link
Contributor

@andrewkolos andrewkolos Aug 7, 2023

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?

Copy link
Contributor Author

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 :)

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@navaronbracke navaronbracke Aug 8, 2023

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.

Copy link
Contributor Author

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.

@navaronbracke
Copy link
Contributor Author

navaronbracke commented Aug 10, 2023

@andrewkolos I had a second look at how the template is rendered.

So we pass things to mustache, that takes care of rendering to the template.

Apparently it has a htmlEscapes property for the template renderer.

Wouldn't it be better if it did the same for yaml?
Then we can also eliminate the manual escapeYamlString for the .metadata file (for the channel & revision variable)

Ref: https://github.com/jonahwilliams/mustache/blob/c4344e0dd45f6605758eb11aa4837859e2c055f0/README.md?plain=1#L39

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.

Copy link
Contributor

@andrewkolos andrewkolos left a 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.

Comment on lines 333 to 377
Copy link
Contributor

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.

Suggested change
// 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);
}
}

Copy link
Contributor Author

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.

Copy link
Contributor

@andrewkolos andrewkolos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@navaronbracke navaronbracke force-pushed the fix_index_content_quotes branch from 3438c6b to 776a44e Compare August 15, 2023 07:48
@navaronbracke
Copy link
Contributor Author

navaronbracke commented Aug 15, 2023

Rebased on ToT to kick off the Google Testing check again

@andrewkolos
Copy link
Contributor

@christopherfujino Are you able to take a look at this?

Comment on lines 364 to 377
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);
}
}
Copy link
Contributor

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?

Suggested change
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)

Copy link
Contributor

@christopherfujino christopherfujino left a 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!

@andrewkolos andrewkolos added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 18, 2023
@auto-submit auto-submit bot merged commit 03664d0 into flutter:master Aug 18, 2023
@navaronbracke navaronbracke deleted the fix_index_content_quotes branch August 18, 2023 06:28
@TahaTesser
Copy link
Member

Thanks for the fix @navaronbracke !

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Web][regression] Meta description has double quotes

4 participants