Commit graph

1209 commits

Author SHA1 Message Date
Julien Bouquillon
ef5bc6c7c3 fix($sniffer): detect transition/animation on older Android browsers
The stock Android browser doesn't support the current for-in body/style
detection for animations and transitions but we can manually fix this.
This is useful for PhoneGap web-views or traditional web-apps using the
stock browser.
2013-07-03 22:16:31 +01:00
Chirayu Krishnappa
5349b20097 fix($parse): disallow access to Function constructor
Enhances sandboxing of Angular Expressions to prevent attacks via:

  {}.toString.constructor(alert("evil JS code"))
2013-07-03 00:03:56 -07:00
Joao Sa
fd87eb0ca5 fix(jqLite): prepend array in correct order
Match jQuery behavior when prepending array into empty element
2013-07-02 23:24:51 -07:00
Igor Minar
69f42b7654 fix($compile): prevent infinite loop w/ replace+transclude directives
Previously if a template contained a directive that had a template
(sync or async) and the directive template was to replace the original
element and the directive template contained another directive on the
root element of this template and this new directive was an element
transclude directive then an infinite recursion would follow because
the compiler kept on re-adding and reapplying the original directive
to the replaced node.

This change fixes that.

Closes #2155
2013-07-02 22:35:39 -07:00
Igor Minar
cbbe3bfe91 revert: fix(compiler): corrects component transclusion on ...
This reverts commit 15e1a29cd0.

The original commit was fixing two issues - one of them was
preventing attributes that triggered directives that replaced
the compiled node to be merged into the new node.

This change was a breaking change (as seen in the diff of the
tests in this commit) and that's why it's being removed.

A proper fix will follow.
2013-07-02 22:35:39 -07:00
Igor Minar
726e0c246b test(ngRepeat): disable an element directive test on IE8 2013-07-02 11:11:52 -07:00
Igor Minar
c46c5924c4 revert: test(ngRepeat): fix IE8 test compatibility issue
This reverts commit 0c6fb665a4.

The change invalidated the test because the point of the the test
was to test that an element directive works. Changing it to attribute
directive was wrong.
2013-07-02 11:07:59 -07:00
Igor Minar
4f0f243771 fix($injector): refactor module loading code and use minErr 2013-07-02 11:05:30 -07:00
Igor Minar
0c6fb665a4 test(ngRepeat): fix IE8 test compatibility issue 2013-07-01 14:30:43 -07:00
joshkurz
807394095b fix(Angular.js): handle duplicate params in parseKeyValue/toKeyValue
parseKeyValue and toKeyValue can now handle duplicate values in the query.
```
?x=1&x=2 <-> {x:[1,2]}
```

The algorithm looks like:
    1)parseKeyValue looks for presence of obj[key]
    2)detects and replaces obj[key] with [obj[key],val]
    3)then pushes more duplicates if necessary
    4)toKeyValue decodes array correctly
    5)(not changed)$location.search({param: 'key'}) still replaces if necessary
    6)(not changed)$location.search({param: ['key1', 'key2']}) sets the url with duplicates

BREAKING CHANGE: Before this change:
- `parseKeyValue` only took the last key overwriting all the previous keys;
- `toKeyValue` joined the keys together in a comma delimited string.
This was deemed buggy behavior. If your server relied on this behavior
then either the server should be fixed or a simple serialization of
the array should be done on the client before passing it to $location.
2013-07-01 19:32:12 +01:00
Chirayu Krishnappa
a22596c925 test($compile): use FQDN for img[src]
img[src]="https://foo" has the unfortunate problem that the browser will
actually try retrieving the resource the non FQDN foo.  The local DNS
might suffix a domain to this, resolve it, and try to present a
certificate for the https request and prompt the user to pick a
certificate. This commit avoids that by making foo a FQDN.  Note that it
might be better to replace foo with example.com (ref
http://tools.ietf.org/html/rfc2606#section-3).
2013-06-28 17:38:11 -07:00
Vojta Jina
89efb12ed8 chore: remove jstd leftovers 2013-06-28 11:43:38 -07:00
Pete Bacon Darwin
bd5c9a0371 style(ngRepeatSpec): fix up colons and iit 2013-06-28 08:28:06 +01:00
Igor Minar
15e1a29cd0 fix(compiler): corrects component transclusion on compilation root.
Closes# 2155
2013-06-27 21:30:24 -07:00
Igor Minar
aef0980063 fix($location): default to / for the url base if no base[href]
With the recent refactoring of $location service we changed this behavior
resulting in a regression.

Previously we thought that html5 mode always required base[href]
to be set in order for urls to resolve properly. It turns out that
base[href] is problematic because it makes anchor urls (#foo) to
always resolve to the base url, which is almost always incorrect
and results in all anchors links and other anchor urls (e.g. svg
references) to be broken.

For this reason, we should now start recommending that people just
deploy to root context (/) and not set the base[href] when using
the html5 mode (push/pop history state).

If it's impossible to deploy to the root context then either all
urls in the app must be absolute or base[href] must be set with the
caveat that anchor urls in such app won't work.

Closes #2762
2013-06-24 22:32:55 -07:00
Chirayu Krishnappa
0960cd0613 test($compile): fix IE specific test. 2013-06-24 21:02:01 -07:00
Chirayu Krishnappa
38deedd6e3 fix($compile): reject multi-expression interpolations for src attribute
BREAKING CHANGE: Concatenating expressions makes it hard to reason about
    whether some combination of concatenated values are unsafe to use
    and could easily lead to XSS.  By requiring that a single expression
    be used for *[src/ng-src] such as iframe[src], object[src], etc.
    (but not img[src/ng-src] since that value is sanitized), we ensure that the value
    that's used is assigned or constructed by some JS code somewhere
    that is more testable or make it obvious that you bound the value to
    some user controlled value.  This helps reduce the load when
    auditing for XSS issues.

    To migrate your code, follow the example below:

        Before:
            JS:
                scope.baseUrl = 'page';
                scope.a = 1;
                scope.b = 2;
            HTML:
                <!-- Are a and b properly escaped here? Is baseUrl
                     controlled by user? -->
                <iframe src="{{baseUrl}}?a={{a}&b={{b}}">

        After:
            JS:
                var baseUrl = "page";
                scope.getIframeSrc = function() {
                  // There are obviously better ways to do this.  The
                  // key point is that one will think about this and do
                  // it the right way.
                  var qs = ["a", "b"].map(function(value, name) {
                      return encodeURIComponent(name) + "=" +
                             encodeURIComponent(value);
                    }).join("&");
                  // baseUrl isn't on scope so it isn't bound to a user
                  // controlled value.
                  return baseUrl + "?" + qs;
                }
            HTML: <iframe src="{{getIframeSrc()}}">
2013-06-24 14:17:18 -07:00
Chirayu Krishnappa
39841f2ec9 fix($compile): disallow interpolations for DOM event handlers
BREAKING CHANGE: Interpolations inside DOM event handlers are
    disallowed.  DOM event handlers execute arbitrary Javascript code.
    Using an interpolation for such handlers means that the interpolated
    value is a JS string that is evaluated.  Storing or generating such
    strings is error prone and likely leads to an XSS if you're not
    super careful.  On the other hand, ng-click and such event handlers
    evaluate Angular expressions that are a lot safer (e.g. No direct
    access to global objects - only scope), cleaner and harder to
    exploit.

    To migrate the code follow the example below:

    Before:

        JS:   scope.foo = 'alert(1)';
        HTML: <div onclick="{{foo}}">

    After:

        JS:   scope.foo = function() { alert(1); }
        HTML: <div ng-click="foo()">
2013-06-21 17:37:44 -07:00
Chirayu Krishnappa
1adf29af13 fix($compile): sanitize values bound to img[src]
Ref: 9532234bf1

BREAKING CHANGE: img[src] URLs are now sanitized using the same whitelist
    as a[href] URLs.  The most obvious impact is if you were using data:
    URIs.  data: URIs will be whitelisted for img[src] in a future
    commit.
2013-06-21 17:26:42 -07:00
Pete Bacon Darwin
8264d08085 fix(Angular.js): don't crash on invalid query parameters 2013-06-20 14:13:16 +01:00
Caio Cunha
53359d549e fix($http): ensure case-insens. header overriding
If user send content-type header, both content-type and default
Content-Type headers were sent. Now default header overriding is
case-insensitive.
2013-06-19 21:30:59 +01:00
Michał Gołębiowski
f1b94b4b59 feat(jqLite): switch bind/unbind to more recent jQuery on/off
jQuery switched to a completely new event binding implementation as of
1.7.0, centering around on/off methods instead of previous bind/unbind.
This patch makes jqLite match this implementation while still supporting
previous bind/unbind methods.
2013-06-19 20:53:24 +01:00
Ken Sheedlo
003861d2fd chore(minErr): replace ngError with minErr 2013-06-17 13:29:30 -07:00
Misko Hevery
4953b49761 fix(ngRepeat): support growing over multi-element groups 2013-06-11 13:14:34 -07:00
Misko Hevery
b28f96949a fix($compile): support multi-element group over text nodes 2013-06-11 13:14:34 -07:00
Matias Niemelä
9faabd1ba0 chore(AngularPublic): remove angular.noConflict feature 2013-06-06 22:06:50 -07:00
Igor Minar
5599b55b04 refactor($route): pull $route and friends into angular-route.js
$route, $routeParams and ngView have been pulled from core angular.js
to angular-route.js/ngRoute module.

This is was done to in order keep the core focused on most commonly
used functionality and allow community routers to be freely used
instead of $route service.

There is no need to panic, angular-route will keep on being supported
by the angular team.

Note: I'm intentionally not fixing tutorial links. Tutorial will need
bigger changes and those should be done when we update tutorial to
1.2.

BREAKING CHANGE: applications that use $route will now need to load
angular-route.js file and define dependency on ngRoute module.

Before:

```
...
<script src="angular.js"></script>
...
var myApp = angular.module('myApp', ['someOtherModule']);
...
```

After:

```
...
<script src="angular.js"></script>
<script src="angular-route.js"></script>
...
var myApp = angular.module('myApp', ['ngRoute', 'someOtherModule']);
...
```

Closes #2804
2013-06-06 17:07:12 -07:00
Jeff Cross
e1a050e6b2 fix(jqLite): Added optional name arg in removeData
jQuery's API for removeData allows a second 'name' argument to just
remove the property by that name from an element's data. The absence
of this argument was causing some features not to work correctly when
combining multiple directives, such as ng-click, ng-show, and ng-animate.
2013-05-30 23:43:27 -07:00
Matias Niemelä
a4b9a6aca9 fix($animator): ensure $animator calculates the highest duration + delay for and transitions and animations together 2013-05-30 22:01:42 -07:00
Misko Hevery
e46100f709 feat($compile): support multi-element directive
By appending  directive-start and directive-end to a
directive it is now possible to have the directive
act on a group of elements.

It is now possible to iterate over multiple elements like so:

<table>
  <tr ng-repeat-start="item in list">I get repeated</tr>
  <tr ng-repeat-end>I also get repeated</tr>
</table>
2013-05-28 22:28:32 -07:00
Igor Minar
b8ea7f6aba feat(ngError): add error message compression and better error messages
- add toThrowNg matcher
2013-05-24 17:03:21 -07:00
Vojta Jina
88eaea8e7b test(matchers): update toThrow matcher 2013-05-24 16:57:15 -07:00
Braden Shepherdson
f4c6b2c789 feat($swipe): Refactor swipe logic from ngSwipe to $swipe service.
This new service is used by the ngSwipeLeft/Right directives, and by the
separate ngCarousel and swipe-to-delete directives which are under
development.
2013-05-23 16:07:44 -07:00
Alexander Shtuchkin
05772e15fb feat($resource): expose promise instead of only $then
- Instance or collection have `$promise` property which is the initial promise.
- Add per-action `interceptor`, which has access to entire $http response object.

BREAKING CHANGE: resource instance does not have `$then` function anymore.

Before:

Resource.query().$then(callback);

After:

Resource.query().$promise.then(callback);

BREAKING CHANGE: instance methods return the promise rather than the instance itself.

Before:

resource.$save().chaining = true;

After:

resource.$save();
resourve.chaining = true;

BREAKING CHANGE: On success, promise is resolved with the resource instance rather than http
response object.

Use interceptor to access the http response object.

Before:

Resource.query().$then(function(response) {...});

After:

var Resource = $resource('/url', {}, {
  get: {
    method: 'get',
    interceptor: {
      response: function(response) {
        // expose response
        return response;
      }
    }
  }
});
2013-05-23 14:18:29 -07:00
Michał Gołębiowski
da5f537ccd fix(jqLite): correctly monkey-patch core jQuery methods
When real jQuery is present, Angular monkey patch it to fire `$destroy` event.

This commit fixes two issues in the jQuery patch:
- passing a selector to the $.fn.remove method (only fire `$destroy` on the matched elements)
- using `$.fn.html` without parameters as a getter (do not fire `$destroy`)
2013-05-23 12:05:55 -07:00
Matias Niemelä
2f571a9c83 chore(ngdocs): move angular-bootstrap.js to be generated only inside the docs and remove from the build process 2013-05-20 14:27:34 -07:00
David Bennett
9f4f593711 feat($http): add support for aborting via timeout promises
If the timeout argument is a promise, abort the request when it is resolved.
Implemented by adding support to $httpBackend service and $httpBackend mock
service.

This api can also be used to explicitly abort requests while keeping the
communication between the deffered and promise unidirectional.

Closes #1159
2013-05-20 14:15:04 -07:00
Zach Snow
2a7043fa23 test($parse): improve clarity of ternary tests 2013-05-17 06:46:09 +01:00
Matias Niemelä
c53d4c9430 feat($animator): provide support for custom animation events 2013-05-16 16:17:46 -07:00
Matias Niemelä
24ed61cf5c test($animator): ensure invalid $sniffer.transitions and $sniffer.animations flags are caught in animation spec code 2013-05-16 16:17:46 -07:00
Julie
0401a7f598 fix(jqLite): pass a dummy event into triggerHandler
Previously, anchor elements could not be used with triggerHandler because
triggerHandler passes null as the event, and any anchor element with an empty
href automatically calls event.preventDefault(). Instead, pass a dummy event
when using triggerHandler, similar to what full jQuery does. Modified from
PR #2379.
2013-05-16 16:15:31 -07:00
Zach Snow
6798fec439 feat($parse): add support for ternary operators to parser
Add '?' token to lexer, add ternary rule to parser at
(hopefully) proper precedence and associativity (based
on https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Operator_Precedence).
Since (exp1 && exp2 || exp3) is supported by the parser,
and (exp1 ? exp2 : exp3) works the same way, it seems
reasonable to add this minor form of control to templates
(see #719).
2013-05-16 22:30:37 +01:00
Ryan Schumacher
cefbcd470d fix($resource): null default param results in TypeError
Fixes issue when setting a default param as `null` error
`TypeError: Cannot read property 'charAt' of null`
2013-05-16 14:26:08 -07:00
Daniel Stockton
f9b897de4b feat($http): add a default content type for PATH requests
The default header is now application/json which while not perfect
in all cases is better than the browser default application/xml.

The new headers also makes for better compatibility with Rails 4
2013-05-16 14:05:05 -07:00
Samuel Santos
d551d72924 feat(ngSrcset): add new ngSrcset directive
In line with ngSrc and ngHref, this new directive ensures that the
`srcset` HTML5 attribute does not include a pre-interpolated string.
Without it the browser will fetch from the URL with the literal text
`{{hash}}` until AngularJS replaces the expression inside `{{hash}}`.

Closes #2601
2013-05-14 21:29:21 +01:00
Andreas Marek
629fb37351 feat(scenario): adds mousedown and mouseup event triggers to scenario
Added mousedown and mouseup event triggers to scenadio dsl 'element' expression.
Added mousedown and mouseup to the custom jquery trigger method to generate real events.
2013-05-14 20:50:36 +01:00
Glenn Goodrich
53061363c7 feat($resource): collapse empty suffix parameters correctly
Previously only repeated `/` delimiters were collapsed into a
single `/`.  Now, the sequence `/.` at the end of the template, i.e.
only followed by a sequence of word characters, is collapsed into a single
`.`. This makes it easier to support suffixes on resource URLs.
For example, given a resource template of `/some/path/:id.:format`, if
the `:id` is `""` but format `"json"` then the URL is now
`/some/path.json`, rather than `/some/path/.json`.

BREAKING CHANGE: A `/` followed by a `.`, in the last segment of the
URL template is now collapsed into a single `.` delimiter. For example:
`users/.json` will become `users.json`. If your server relied upon this
sequence then it will no longer work. In this case you can now escape the
`/.` sequence with `/\.`
2013-05-14 20:01:15 +01:00
quazzie
c32a859bdb feat(select): match options by expression other than object identity
Extend ng-options with a new clause, "track by [trackByExpression]", which can be used when
working with objects.  The `trackByExpression` should uniquely identify select options objects.
This solves the problem of previously having to match ng-options objects by identity.
You can now write: `ng-options="obj as obj.name for obj in objects track by obj.id"`
The "track by" expression will be used when checking for equality of objects.

Examples:
<select
    ng-model="user.favMovieStub"
    ng-options="movie as movie.name for movie in movies track by movie.id">
</select>

scope: {
  user: { name: 'Test user', favMovieStub: { id: 1, name: 'Starwars' } }
  movies: [{ id: 1, name: 'Starwars', rating: 5, ... }, { id: 13, ... }]
}

The select input will match user favMovieStub to the first movie in the movies array, and show
"Star Wars" as the selected item.
2013-05-14 19:58:05 +01:00
Matias Niemelä
4acc28a310 feat(ngAnimate): cancel previous incomplete animations when new animations take place 2013-05-13 21:09:43 -07:00
Matias Niemelä
0930d9dfe7 chore($sniffer): replace remaining supportsTransitions/supportsAnimations flags inside tests 2013-05-13 18:12:25 -04:00