aboutsummaryrefslogtreecommitdiffstats
path: root/test/ng/compileSpec.js
AgeCommit message (Collapse)Author
2013-08-03feat($compile): support compile animation hooks classesMatias Niemelä
2013-07-31feat(directive): support as instance syntaxLucas Galfasó
Support controller: 'MyController as my' syntax for directives which publishes the controller instance to the directive scope. Support controllerAs syntax to define an alias to the controller within the directive scope.
2013-07-31feat(directive): support as instance syntaxLucas Galfasó
Support controller: 'MyController as my' syntax for directives which publishes the controller instance to the directive scope. Support controllerAs syntax to define an alias to the controller within the directive scope.
2013-07-28test($compile): fix spelling error in assertion (ngAttr*)Brian Fitzpatrick
The string 'test2' should be 'test3' as 'test2' has already been tested with the previous assertion.
2013-07-26feat(ngAnimate): complete rewrite of animationsMatias Niemelä
- ngAnimate directive is gone and was replaced with class based animations/transitions - support for triggering animations on css class additions and removals - done callback was added to all animation apis - $animation and $animator where merged into a single $animate service with api: - $animate.enter(element, parent, after, done); - $animate.leave(element, done); - $animate.move(element, parent, after, done); - $animate.addClass(element, className, done); - $animate.removeClass(element, className, done); BREAKING CHANGE: too many things changed, we'll write up a separate doc with migration instructions
2013-07-25feat($sce): new $sce service for Strict Contextual Escaping.Chirayu Krishnappa
$sce is a service that provides Strict Contextual Escaping services to AngularJS. Strict Contextual Escaping -------------------------- Strict Contextual Escaping (SCE) is a mode in which AngularJS requires bindings in certain contexts to result in a value that is marked as safe to use for that context One example of such a context is binding arbitrary html controlled by the user via ng-bind-html-unsafe. We refer to these contexts as privileged or SCE contexts. As of version 1.2, Angular ships with SCE enabled by default. Note: When enabled (the default), IE8 in quirks mode is not supported. In this mode, IE8 allows one to execute arbitrary javascript by the use of the expression() syntax. Refer http://blogs.msdn.com/b/ie/archive/2008/10/16/ending-expressions.aspx to learn more about them. You can ensure your document is in standards mode and not quirks mode by adding <!doctype html> to the top of your HTML document. SCE assists in writing code in way that (a) is secure by default and (b) makes auditing for security vulnerabilities such as XSS, clickjacking, etc. a lot easier. Here's an example of a binding in a privileged context: <input ng-model="userHtml"> <div ng-bind-html-unsafe="{{userHtml}}"> Notice that ng-bind-html-unsafe is bound to {{userHtml}} controlled by the user. With SCE disabled, this application allows the user to render arbitrary HTML into the DIV. In a more realistic example, one may be rendering user comments, blog articles, etc. via bindings. (HTML is just one example of a context where rendering user controlled input creates security vulnerabilities.) For the case of HTML, you might use a library, either on the client side, or on the server side, to sanitize unsafe HTML before binding to the value and rendering it in the document. How would you ensure that every place that used these types of bindings was bound to a value that was sanitized by your library (or returned as safe for rendering by your server?) How can you ensure that you didn't accidentally delete the line that sanitized the value, or renamed some properties/fields and forgot to update the binding to the sanitized value? To be secure by default, you want to ensure that any such bindings are disallowed unless you can determine that something explicitly says it's safe to use a value for binding in that context. You can then audit your code (a simple grep would do) to ensure that this is only done for those values that you can easily tell are safe - because they were received from your server, sanitized by your library, etc. You can organize your codebase to help with this - perhaps allowing only the files in a specific directory to do this. Ensuring that the internal API exposed by that code doesn't markup arbitrary values as safe then becomes a more manageable task. In the case of AngularJS' SCE service, one uses $sce.trustAs (and shorthand methods such as $sce.trustAsHtml, etc.) to obtain values that will be accepted by SCE / privileged contexts. In privileged contexts, directives and code will bind to the result of $sce.getTrusted(context, value) rather than to the value directly. Directives use $sce.parseAs rather than $parse to watch attribute bindings, which performs the $sce.getTrusted behind the scenes on non-constant literals. As an example, ngBindHtmlUnsafe uses $sce.parseAsHtml(binding expression). Here's the actual code (slightly simplified): var ngBindHtmlUnsafeDirective = ['$sce', function($sce) { return function(scope, element, attr) { scope.$watch($sce.parseAsHtml(attr.ngBindHtmlUnsafe), function(value) { element.html(value || ''); }); }; }]; Impact on loading templates --------------------------- This applies both to the ng-include directive as well as templateUrl's specified by directives. By default, Angular only loads templates from the same domain and protocol as the application document. This is done by calling $sce.getTrustedResourceUrl on the template URL. To load templates from other domains and/or protocols, you may either either whitelist them or wrap it into a trusted value. *Please note*: The browser's Same Origin Policy and Cross-Origin Resource Sharing (CORS) policy apply in addition to this and may further restrict whether the template is successfully loaded. This means that without the right CORS policy, loading templates from a different domain won't work on all browsers. Also, loading templates from file:// URL does not work on some browsers. This feels like too much overhead for the developer? ---------------------------------------------------- It's important to remember that SCE only applies to interpolation expressions. If your expressions are constant literals, they're automatically trusted and you don't need to call $sce.trustAs on them. e.g. <div ng-html-bind-unsafe="'<b>implicitly trusted</b>'"></div> just works. Additionally, a[href] and img[src] automatically sanitize their URLs and do not pass them through $sce.getTrusted. SCE doesn't play a role here. The included $sceDelegate comes with sane defaults to allow you to load templates in ng-include from your application's domain without having to even know about SCE. It blocks loading templates from other domains or loading templates over http from an https served document. You can change these by setting your own custom whitelists and blacklists for matching such URLs. This significantly reduces the overhead. It is far easier to pay the small overhead and have an application that's secure and can be audited to verify that with much more ease than bolting security onto an application later.
2013-07-22fix($compile): always instantiate controllers in parent->child orderIgor Minar
Previously it was possible to get into a situation where child controller was being instantiated before parent which resulted in an error. Closes #2738
2013-07-18fix($compile): allow data: image URIs in img[src]Chirayu Krishnappa
Ref: 1adf29af13890d61286840177607edd552a9df97 BREAKING CHANGE: img[src] URLs are now sanitized via a separate whitelist regex instead of sharing the whitelist regex with a[href]. With this change, img[src] URLs may also be data: URI's matching mime types image/*. mailto: URLs are disallowed (and do not make sense for img[src] but were allowed under the a[href] whitelist used before.)
2013-07-02revert: fix(compiler): corrects component transclusion on ...Igor Minar
This reverts commit 15e1a29cd08993b599f390e83a249ec17f753972. 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-06-28test($compile): use FQDN for img[src]Chirayu Krishnappa
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-27fix(compiler): corrects component transclusion on compilation root.Igor Minar
Closes# 2155
2013-06-21fix($compile): disallow interpolations for DOM event handlersChirayu Krishnappa
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-21fix($compile): sanitize values bound to img[src]Chirayu Krishnappa
Ref: 9532234bf1c408af9a6fd2c4743fdb585b920531 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-17chore(minErr): replace ngError with minErrKen Sheedlo
2013-06-11fix($compile): support multi-element group over text nodesMisko Hevery
2013-05-28feat($compile): support multi-element directiveMisko Hevery
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-24feat(ngError): add error message compression and better error messagesIgor Minar
- add toThrowNg matcher
2013-04-29test(browser/compile): fix calls to Jasmine fail()Oren Avissar
The fail() function in Jasmine expects an Error object parameter. Also, there is no global alias for fail() so it must be accessed using `this.fail(new Error())`.
2013-02-28feat($compile): allow directives to modify interpolated attributesThibault Leruitte
A directive can now set/update/remove attribute values even those containing interpolation during the compile phase and have the new value be picked up during the compilation. For example in template: <div replace-directive some-attr-or-directive="{{originalInterpolationValue}}"></div> the replace-directive can now replace the value of some-attr-or-directive during compilation which produces this intermitent template: <div replace-directive some-attr-or-directive="{{replacedInterpolationValue}}"></div> or even <div replace-directive some-attr-or-directive="replacedStaticValue"></div> as well as <div replace-directive some-attr-or-directive></div>
2013-02-27feat($compile): support for dynamic template generationLuis Ramón López
`template` and `templateUrl` properties can now be optionally defined via a function. This allows templates to be dynamically generated on the fly.
2013-02-27feat($compile): add attribute binding support via ngAttr*Luis Ramón López
Sometimes is not desirable to use interpolation on attributes because the user agent parses them before the interpolation takes place. I.e: <svg> <circle cx="{{cx}}" cy="{{cy}}" r="{{r}}"></circle> </svg> The snippet throws three browser errors, one for each attribute. For some attributes, AngularJS fixes that behaviour introducing special directives like ng-href or ng-src. This commit is a more general solution that allows prefixing any attribute with "ng-attr-", "ng:attr:" or "ng_attr_" so it will be set only when the binding is done. The prefix is then removed. Example usage: <svg> <circle ng-attr-cx="{{cx}}" ng-attr-cy="{{cy}}" ng:attr-r="{{r}}"></circle> </svg> Closes #1050 Closes #1925
2013-02-25fix($compile): compile replace directives in external templatedanilsomsikov
Passing DOMNode#childNodes to compileNodes when compiling remote template, so that directives with replace:true can be compiled. The previous version used jqLite#contents which returned collection that was not updated during the compilation. Closes #1859
2013-02-25chore(sortedHtml): print attributes with empty valueIgor Minar
I had to also fix some tests as they started failing on IE8. We should figure out why these extra attributes are set in IE8, but I'm too tired of IE to worry about it now. Since I'm not introducing this issue just making it visible, I'm going to commit this as is.
2013-02-25feat($compile): '=?' makes '=' binding optionalLuis Ramón López
If you bind using '=' to a non-existant parent property, the compiler will throw a NON_ASSIGNABLE_MODEL_EXPRESSION exception, which is right because the model doesn't exist. This enhancement allow to specify that a binding is optional so it won't complain if the parent property is not defined. In order to mantain backward compability, the new behaviour must be specified using '=?' instead of '='. The local property will be undefined is these cases. Closes #909 Closes #1435
2013-02-25fix($compile): whitelist file:// in url sanitizationIgor Minar
2013-02-23fix($compile): handle elements with no childNodes propertyIgor Minar
see the test for more details
2013-02-20fix($compile): sanitize values bound to a[href]Igor Minar
2013-02-18fix(compile): should not leak memory when there are top level empty text nodesPete Bacon Darwin
The change to prevent <span> elements being wrapped around empty text nodes caused these empty text nodes to have scopes and controllers attached, through jqLite.data() calls, which led to memory leaks and errors in IE8. Now we exclude all but document nodes and elements from having jqLite.data() set both in the compiler and in ng-view. Fixes: #1968 and #1876
2013-02-14fix(compile): Initialize interpolated attributes before directive linkingPete Bacon Darwin
2013-02-14fix(compile): Interpolate @ locals before the link function runsPete Bacon Darwin
Do a one-off interpolation of @ locals to ensure that the link fn receives attributes that are already interpolated.
2013-02-07fix($compile): rename $compileNote to compileNodeEnrique Paredes
Directives was observing different instances of Attributes than the one that interpolation was registered with because we failed to realize that the compile node and link node were the same (one of them was a wrapper rather than raw node) Closes #1941
2013-01-30feat(Scope): expose transcluded and isolate scope info for batarangBrian Ford
test($compile): add test for exposing transclude and isolate scope info to batarang
2013-01-17fix($compile): do not wrap empty root text nodes in spansPete Bacon Darwin
Closes #1059
2013-01-14fix($compile): safely create transclude comment nodesIgor Minar
Closes #1740
2013-01-09feat($compile): support modifying the DOM structure in postlink fnMartin Probst
Support modifying the DOM structure in the post link function of a directive by creating a defensive copy of the node list, as opposed to a live DOM list. This is useful for directives to actually replace their entire DOM fragment, e.g. with the HTML fragment generated by a 3rd party component (Closure, Bootstrap ...). Fix the indentation of the compileNodes function (was one too little).
2012-10-29fix($compile): prevent double attr interpolation w/ templateUrlIgor Minar
This fixes the issue that caused two attr interpolation observers to be registered for the same attribute as a result of isolate scope definition with attr (@) property for this attribute. Duplicate observers would then fight with each other updating the model. The issue occured only when this directive was used in a repeater because that's when we clone the template node which caused the two observers to point to two different sets of $attr instances. Closes #1166, #836
2012-09-20fix($compile): reference local in isolate scopeVojta Jina
This was really corner case: Watcher needs to return changed value, to notify that model might have changed and one more $digest cycle needs to be performed. The watcher, that takes care of reference binding into an isolate scope ("="), did not return changed value, if the change was from the isolate scope to the parent. If any other watcher returned change, it worked fine, as this change caused re-digest. Closes #1272
2012-08-13fix($compile): denormalize directive templatesIgor Minar
Since developers are allowed to customize start/end interpolation strings, but third-party directive creators don't know about these customizations, we should standardize on {{ }} in templates of reusable (third-party) directives. During the compilation, these templates are then denormalized to use whatever the custom start/end symbol is, effectively translating the template into the syntax of the runtime environment. This addresses an issue raised at http://goo.gl/e8VPV Existing code should not be affected by this change since project that do use custom interpolation markers are not expected to use {{ }} in existing directive templates.
2012-08-13refactor($compile): code cleanupIgor Minar
2012-06-08fix($compile): correctly merge class attr for replace directivesMax Martinsson
Merging of interpolated class attribute from directive template with replace:true works Closes #1006
2012-06-08feat($compile): simplify isolate scope bindingsMisko Hevery
Changed the isolate scope binding options to: - @attr - attribute binding (including interpolation) - =model - by-directional model binding - &expr - expression execution binding This change simplifies the terminology as well as number of choices available to the developer. It also supports local name aliasing from the parent. BREAKING CHANGE: isolate scope bindings definition has changed and the inject option for the directive controller injection was removed. To migrate the code follow the example below: Before: scope: { myAttr: 'attribute', myBind: 'bind', myExpression: 'expression', myEval: 'evaluate', myAccessor: 'accessor' } After: scope: { myAttr: '@', myBind: '@', myExpression: '&', // myEval - usually not useful, but in cases where the expression is assignable, you can use '=' myAccessor: '=' // in directive's template change myAccessor() to myAccessor } The removed `inject` wasn't generaly useful for directives so there should be no code using it.
2012-06-08fix(startingTag): make tag name always lowercaseIgor Minar
some browsers (IE) always provide the nodeName as upper-case
2012-06-08refactor($compile): always call attr.$observeMisko Hevery
attr.$observe used to call function only if there was interpolation on that attribute. We now call the observation function all the time but we only save the reference to it if interpolation is present.
2012-06-08chore($compile): clean up compiler testsMisko Hevery
2012-05-04fix($compile): have $observe return registration functionMisko Hevery
2012-05-04fix($compile): ignore ws when checking if template has single rootIgor Minar
Also add the same error checking for sync templates. Closes #910
2012-05-03style($compile): clean up the code and normalize fn namesIgor Minar
2012-05-03fix($compile): attach scope to the directive element when templateUrl and ↵Igor Minar
replace=true We forgot to reattach the scope to the replacement element. This affected only directives that had templateUrl and replace:true properties. Reported on the mailing list: https://groups.google.com/forum/?fromgroups#!topic/angular/zwjLr1msS2Y http://jsfiddle.net/lukebayes/g9Sh9/
2012-05-03chore($compile): remove obsolete <<CONTENT>> transclusionIgor Minar
This stuff was never documented and is an accidental leftover from the time when the compiler was rewritten. If any code depends on this, it should be rewritten to use ngTransclude directive intead.
2012-05-03fix($compile): prevent duplicate directive controller instantiationIgor Minar
Closes #876