Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix($compile): ignore optional =-bound properties with empty value #12290

Closed
wants to merge 2 commits into from

Conversation

caitp
Copy link
Contributor

@caitp caitp commented Jul 7, 2015

Previously, optional empty '='-bound expressions were ignored ---
erroneously they stopped being ignored, and no tests were caused to fail
for this reason. This change restores the original ignoring behaviour while
still preventing other errors fixed by 8a1eb16

Closes #12144
Closes #12259

@caitp
Copy link
Contributor Author

caitp commented Jul 7, 2015

@petebacondarwin / @jeffbcross PTAL --- I've tested this against the angular-material tests and it seems to be working okay, but I'm not sure what the issue was with the tab control (so it would be good to get another look just in case there's another sneaky bug)

Previously, optional empty '='-bound expressions were ignored ---
erroneously they stopped being ignored, and no tests were caused to
fail for this reason. This change restores the original ignoring
behaviour while still preventing other errors fixed by 8a1eb16

Closes angular#12144
Closes angular#12259
@Narretz
Copy link
Contributor

Narretz commented Jul 7, 2015

Thanks @caitp ! It looks like @ThomasBurleson is involved with this, too.

@caitp
Copy link
Contributor Author

caitp commented Jul 7, 2015

is travis really being this slow today? wow

@@ -2592,11 +2587,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
break;

case '=':
if (optional && !attrs[attrName]) {
return;
if (!hasOwnProperty.call(attrs, attrName)) {
Copy link
Member

Choose a reason for hiding this comment

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

Why not just use attrs.hasOwnProperty (instead of hasOwnProperty.call(attrs) here and above ?
(It is being used below anyway ;))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

attrs shouldn't share [[Prototype]] with Object, there are a lot of bugs which have been fixed because of this. the code below just came from a revert of a revert, so it's part of the pieces that haven't been fixed yet

Choose a reason for hiding this comment

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

@caitp - in #12144 (comment) you mentioned some additional code required for Angular Material.

  • Is that still true?
  • If yes, should we modify the Angular Material directives with optional 2-way binding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code in that snippet is contained in the second commit here, just organized slightly differently --- I decided to avoid the isString() check and just test if it's falsy (values in attrs should always be a string, unless it gets shadowed above, in which case it's undefined --- so also falsy) --- so the simpler version in this PR should be fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, the example snippet in that issue also handles (ignores) values which are exclusively whitespace, but I think these are pretty rare

Copy link
Member

Choose a reason for hiding this comment

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

@ThomasBurleson - see @caitp's reply to your question, that the code snippet that is mentioned in the previously linked comment is included in this PR. In other words you shouldn't need to make changes to Material for all your (non-disabled) tests to pass.

I think the only thing we can do now is see if this PR works for the latest on Material's master branch and if so then merge this PR.

Choose a reason for hiding this comment

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

@petebacondarwin - Re: ... see if this PR works for the latest on Material's master branch. Is this something I should be doing now; or is someone else assigned this task ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@ThomasBurleson would be nice if you could test that!

Choose a reason for hiding this comment

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

@Narretz - I will test tonight and respond tomorrow. Will that work ?

@petebacondarwin
Copy link
Member

Without running the tests and stuff myself, this LGTM

@caitp
Copy link
Contributor Author

caitp commented Jul 9, 2015

I'm a bit worried that it could break things in ways that aren't being tested in Material. @jeffbcross did you know of any demo apps in material which were affected? The ones I tried all looked fine (for the tabs component, autocomplete component, and chips components)

@jeffbcross
Copy link
Contributor

I don't know any demo apps that were affected, but I have limited familiarity with the material project. Could you give @ThomasBurleson some guidance on where this change could potentially cause problems?

@ThomasBurleson
Copy link

@jeffbcross, @petebacondarwin - see comment https://github.com/angular/angular.js/pull/12290/files#r34271903
I want to make sure I understand the issue, the fix, and any changes needed in Angular Material. Thx.

@matthiasg
Copy link

is this being actively investigated ? we are blocked by this for our next release and would have to change a number of sources to workaround. we would like to avoid that if this is being expected to be merged soon

@petebacondarwin
Copy link
Member

This PR still causes observers to be called with undefined as indicated in #12383. We should probably prevent this.

@caitp
Copy link
Contributor Author

caitp commented Jul 21, 2015

it only does in certain condition, when the listeners are not optional. We don't have a great other way to do this

@Narretz
Copy link
Contributor

Narretz commented Jul 27, 2015

I say, let's merge it in time for 1.4.4. We can always look into this observers fired with undefined thing later.

@matthiasg
Copy link

just merge this in .. this is causing a number of issues already and is making some directives quite cumbersome to write

@petebacondarwin petebacondarwin self-assigned this Jul 29, 2015
@petebacondarwin
Copy link
Member

A project for tomorrow for me. OK

@caitp caitp closed this in 533d9b7 Jul 29, 2015
@petebacondarwin
Copy link
Member

I have merged this and I have a PR for #12383 at #12464

@caitp
Copy link
Contributor Author

caitp commented Jul 29, 2015

Thanks Pete

netman92 pushed a commit to netman92/angular.js that referenced this pull request Aug 8, 2015
Previously, optional empty '='-bound expressions were ignored ---
erroneously they stopped being ignored, and no tests were caused to
fail for this reason. This change restores the original ignoring
behaviour while still preventing other errors fixed by 8a1eb16

Closes angular#12144
Closes angular#12259
Closes angular#12290
ggershoni pushed a commit to ggershoni/angular.js that referenced this pull request Sep 29, 2015
Previously, optional empty '='-bound expressions were ignored ---
erroneously they stopped being ignored, and no tests were caused to
fail for this reason. This change restores the original ignoring
behaviour while still preventing other errors fixed by 8a1eb16

Closes angular#12144
Closes angular#12259
Closes angular#12290
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.