Skip to content
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(core): meta addTag() adds incorrect attribute #32531

Closed
wants to merge 1 commit into from

Conversation

sabeersulaiman
Copy link

Meta::addTag() adds a meta tag with httpEquiv instead of http-equiv when
MetaDefinition contains httpEquiv property.

closes #31525

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Currently when we use the addTag() or addTags() method with a MetaDefinition containing httpEquiv property a meta tag with an incorrect attribute httpequiv will be added instead of the correct http-equiv attribute.

Issue Number: #31525

What is the new behavior?

The changes will add meta tags with the correct attribute.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Creating this PR instead of an old one that I messed up while fixing a conflict: #31542

@sabeersulaiman sabeersulaiman requested a review from a team as a code owner September 7, 2019 14:43
@lazarljubenovic
Copy link
Contributor

I'm not sure if this is a good approach. We should either transform all camelCase to dash-case, or have an easy-to-edit map somewhere, such as map = {httpEquiv: 'http-equiv' }. This code will turn into mess. Or, the user should simply be in charge of properly passing {'http-equiv': ...} if that's what he wants to add to the tag?

@sabeersulaiman
Copy link
Author

@lazarljubenovic agreed, I was expecting something similar to a map before looking into this implementation. But turned out that was not the approach, if users should be held incharge then I think we should drop httpEquiv from the model and have docs pointing to the same

@sabeersulaiman
Copy link
Author

But removing httpEquiv can be considered as a breaking change ?

@lazarljubenovic
Copy link
Contributor

lazarljubenovic commented Sep 7, 2019

Hmm, I guess that would be a breaking change indeed, since it would change this part of the public API:

export type MetaDefinition = {
charset?: string; content?: string; httpEquiv?: string; id?: string; itemprop?: string;
name?: string;
property?: string;
scheme?: string;
url?: string;
} &
{
// TODO(IgorMinar): this type looks wrong
[prop: string]: string;
};

But currently it misleads the developer by suggesting httpEquiv, which will give a wrong attribute (as you pointed out in #31525).

So, in my opinion, the proper solution to the bug (while avoiding breaking changes) is to introduce a mapping object where it will be easy to later edit keys and add new ones, such as this one.

const META_KEYS_MAP = {
  httpEquiv: 'http-equiv',
}

Then if the attribute's key is not present in the map, assume that the key of MetaDefinition object should be taken as the attribute key.

And since this...

{
// TODO(IgorMinar): this type looks wrong
[prop: string]: string;
};

...exists, the developer can always add custom attributes by specifying the dash himself.

@sabeersulaiman
Copy link
Author

@lazarljubenovic I am gonna go with the approach you suggested as it is cleaner and does not introduce a breaking change.

Meta::addTag() adds a meta tag with httpEquiv attribute instead of http-equiv when
MetaDefinition contains httpEquiv property.
@mhevery
Copy link
Contributor

mhevery commented Nov 20, 2020

presubmit

@mhevery mhevery added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Nov 20, 2020
AndrewKushnir pushed a commit that referenced this pull request Nov 20, 2020
Meta::addTag() adds a meta tag with httpEquiv attribute instead of http-equiv when
MetaDefinition contains httpEquiv property.

PR Close #32531
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Meta class addTag() with httpEquiv MetaDefinition adds incorrect attribute
6 participants