@angular-wave/angular.ts 0.9.3 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/@types/angular.d.ts +4 -19
  2. package/@types/animations/animate.d.ts +2 -2
  3. package/@types/animations/animation.d.ts +1 -1
  4. package/@types/core/compile/attributes.d.ts +1 -1
  5. package/@types/core/compile/compile.d.ts +2 -2
  6. package/@types/core/controller/controller.d.ts +1 -1
  7. package/@types/core/controller/interface.d.ts +6 -0
  8. package/@types/core/di/ng-module.d.ts +27 -26
  9. package/@types/core/filter/filter.d.ts +5 -5
  10. package/@types/core/interpolate/interface.d.ts +13 -0
  11. package/@types/core/interpolate/interpolate.d.ts +1 -13
  12. package/@types/core/scope/scope.d.ts +4 -1
  13. package/@types/directive/http/http.d.ts +16 -16
  14. package/@types/directive/http/interface.d.ts +27 -0
  15. package/@types/directive/include/include.d.ts +4 -4
  16. package/@types/directive/inject/inject.d.ts +12 -0
  17. package/@types/directive/model/model.d.ts +1 -1
  18. package/@types/directive/script/script.d.ts +2 -2
  19. package/@types/directive/setter/setter.d.ts +4 -4
  20. package/@types/filters/filter.d.ts +2 -2
  21. package/@types/filters/filters.d.ts +2 -2
  22. package/@types/filters/interface.d.ts +8 -0
  23. package/@types/filters/limit-to.d.ts +2 -2
  24. package/@types/filters/order-by.d.ts +2 -2
  25. package/@types/index.d.ts +84 -1
  26. package/@types/interface.d.ts +105 -82
  27. package/@types/router/state/interface.d.ts +8 -8
  28. package/@types/router/state-filters.d.ts +4 -4
  29. package/@types/router/template-factory.d.ts +6 -6
  30. package/@types/router/transition/hook-builder.d.ts +5 -2
  31. package/@types/router/transition/hook-registry.d.ts +11 -2
  32. package/@types/router/transition/transition-service.d.ts +6 -2
  33. package/@types/router/transition/transition.d.ts +2 -2
  34. package/@types/router/view/view.d.ts +1 -8
  35. package/@types/router/view-scroll.d.ts +4 -2
  36. package/@types/services/{anchor-scroll.d.ts → anchor-scroll/anchor-scroll.d.ts} +2 -2
  37. package/@types/services/exception/exception-handler.d.ts +2 -2
  38. package/@types/services/exception/interface.d.ts +1 -1
  39. package/@types/services/http/http.d.ts +40 -2
  40. package/@types/services/http/interface.d.ts +11 -0
  41. package/@types/services/location/location.d.ts +1 -4
  42. package/@types/services/sce/sce.d.ts +3 -4
  43. package/@types/services/template-cache/template-cache.d.ts +4 -4
  44. package/@types/services/template-request/interface.d.ts +22 -0
  45. package/@types/services/{template-request.d.ts → template-request/template-request.d.ts} +4 -7
  46. package/@types/shared/common.d.ts +8 -69
  47. package/@types/shared/hof.d.ts +7 -7
  48. package/dist/angular-ts.esm.js +509 -569
  49. package/dist/angular-ts.umd.js +509 -569
  50. package/dist/angular-ts.umd.min.js +1 -1
  51. package/{src/filters → docs/content/docs/filter}/filter.md +18 -9
  52. package/{src/filters → docs/content/docs/filter}/json.md +6 -3
  53. package/docs/content/docs/filter/limit-to.md +30 -0
  54. package/docs/content/docs/filter/order-by.md +123 -0
  55. package/docs/content/docs/provider/sceProvider.md +194 -0
  56. package/docs/content/docs/provider/templateRequestProvider.md +5 -0
  57. package/docs/content/docs/service/compile.md +5 -0
  58. package/docs/content/docs/service/controller.md +5 -0
  59. package/docs/content/docs/service/http.md +161 -0
  60. package/docs/content/docs/service/interpolation.md +5 -0
  61. package/docs/content/docs/service/log.md +1 -1
  62. package/docs/content/docs/service/parse.md +5 -0
  63. package/docs/content/docs/service/rootElement.md +5 -0
  64. package/docs/content/docs/service/rootScope.md +5 -0
  65. package/docs/content/docs/service/sce.md +194 -0
  66. package/docs/content/docs/service/templateRequest.md +5 -0
  67. package/docs/content/docs/values/_index.md +4 -0
  68. package/docs/content/docs/values/document.md +29 -0
  69. package/docs/content/docs/values/window.md +29 -0
  70. package/docs/layouts/shortcodes/version.html +1 -1
  71. package/docs/static/examples/document/document.html +3 -0
  72. package/docs/static/examples/i18n/i18n.html +77 -0
  73. package/docs/static/examples/window/window.html +4 -0
  74. package/docs/static/typedoc/assets/hierarchy.js +1 -1
  75. package/docs/static/typedoc/assets/highlight.css +0 -49
  76. package/docs/static/typedoc/assets/navigation.js +1 -1
  77. package/docs/static/typedoc/assets/search.js +1 -1
  78. package/docs/static/typedoc/classes/PubSubProvider.html +3 -2
  79. package/docs/static/typedoc/classes/TemplateCacheProvider.html +1 -1
  80. package/docs/static/typedoc/hierarchy.html +1 -1
  81. package/docs/static/typedoc/index.html +1 -1
  82. package/docs/static/typedoc/interfaces/HttpProviderDefaults.html +1 -1
  83. package/docs/static/typedoc/interfaces/RequestConfig.html +1 -1
  84. package/docs/static/typedoc/interfaces/RequestShortcutConfig.html +1 -1
  85. package/docs/static/typedoc/interfaces/ServiceProvider.html +3 -3
  86. package/docs/static/typedoc/types/HttpParamSerializer.html +2 -0
  87. package/docs/static/typedoc/types/{Expression.html → HttpParams.html} +1 -5
  88. package/legacy.d.ts +0 -921
  89. package/package.json +1 -1
  90. package/src/angular.js +2 -9
  91. package/src/animations/animate.js +1 -1
  92. package/src/animations/animation.js +7 -7
  93. package/src/core/compile/compile.js +3 -2
  94. package/src/core/controller/controller.js +10 -6
  95. package/src/core/controller/interface.ts +6 -0
  96. package/src/core/di/injector.js +1 -1
  97. package/src/core/di/internal-injector.js +2 -0
  98. package/src/core/di/ng-module.js +16 -13
  99. package/src/core/filter/filter.js +3 -3
  100. package/src/core/interpolate/interface.ts +14 -0
  101. package/src/core/interpolate/interpolate.js +7 -5
  102. package/src/core/scope/scope.js +4 -1
  103. package/src/directive/http/delete.spec.js +5 -8
  104. package/src/directive/http/http.js +16 -16
  105. package/src/directive/http/interface.ts +36 -0
  106. package/src/directive/http/put.spec.js +5 -8
  107. package/src/directive/include/include.js +2 -2
  108. package/src/{services/http-backend/http-backend.html → directive/inject/inject.html} +1 -4
  109. package/src/directive/inject/inject.js +35 -0
  110. package/src/directive/inject/inject.spec.js +108 -0
  111. package/src/{services/http-backend/http-backend.test.js → directive/inject/inject.test.js} +1 -1
  112. package/src/directive/script/script.js +1 -1
  113. package/src/directive/setter/setter.js +2 -2
  114. package/src/filters/filter.js +1 -1
  115. package/src/filters/filters.js +1 -1
  116. package/src/filters/interface.ts +9 -0
  117. package/src/filters/limit-to.js +1 -1
  118. package/src/filters/order-by.js +1 -1
  119. package/src/index.ts +96 -0
  120. package/src/injection-tokens.js +4 -1
  121. package/src/interface.ts +102 -93
  122. package/src/ng.js +6 -4
  123. package/src/ng.spec.js +12 -0
  124. package/src/router/directives/state-directives.js +1 -1
  125. package/src/router/directives/view-directive.spec.js +19 -35
  126. package/src/router/state/interface.ts +8 -8
  127. package/src/router/state/state-builder.js +4 -4
  128. package/src/router/state/state-registry.js +7 -2
  129. package/src/router/state/state-service.js +2 -14
  130. package/src/router/state-filters.js +2 -2
  131. package/src/router/template-factory.js +3 -3
  132. package/src/router/template-factory.spec.js +10 -19
  133. package/src/router/transition/hook-builder.js +5 -1
  134. package/src/router/transition/hook-registry.js +12 -3
  135. package/src/router/transition/transition-service.js +4 -9
  136. package/src/router/transition/transition.js +3 -2
  137. package/src/router/url/url-service.js +2 -2
  138. package/src/router/view/view.js +3 -15
  139. package/src/router/view-scroll.js +2 -2
  140. package/src/services/{anchor-scroll.js → anchor-scroll/anchor-scroll.js} +4 -4
  141. package/src/services/exception/exception-handler.js +1 -1
  142. package/src/services/exception/interface.ts +1 -1
  143. package/src/services/http/http.js +200 -13
  144. package/src/services/http/http.spec.js +388 -9
  145. package/src/services/http/interface.ts +13 -0
  146. package/src/services/location/location.js +1 -1
  147. package/src/services/sce/sce.js +18 -13
  148. package/src/services/template-cache/template-cache.js +2 -2
  149. package/src/services/template-request/interface.ts +23 -0
  150. package/src/services/{template-request.js → template-request/template-request.js} +6 -6
  151. package/src/shared/common.js +7 -80
  152. package/src/shared/hof.js +23 -17
  153. package/typedoc.json +1 -1
  154. package/@types/services/cookie-reader.d.ts +0 -4
  155. package/@types/services/http-backend/http-backend.d.ts +0 -58
  156. package/@types/services/template-cache/interface.d.ts +0 -10
  157. package/docs/static/typedoc/interfaces/ChangesObject.html +0 -6
  158. package/docs/static/typedoc/interfaces/ComponentOptions.html +0 -16
  159. package/docs/static/typedoc/interfaces/Controller.html +0 -12
  160. package/docs/static/typedoc/interfaces/Directive.html +0 -37
  161. package/docs/static/typedoc/interfaces/DirectivePrePost.html +0 -4
  162. package/docs/static/typedoc/interfaces/NgModelController.html +0 -30
  163. package/docs/static/typedoc/interfaces/NgModelOptions.html +0 -16
  164. package/docs/static/typedoc/interfaces/Provider.html +0 -34
  165. package/docs/static/typedoc/interfaces/TemplateCache.html +0 -7
  166. package/docs/static/typedoc/interfaces/TranscludeFunctionObject.html +0 -8
  167. package/docs/static/typedoc/types/AnnotatedDirectiveFactory.html +0 -1
  168. package/docs/static/typedoc/types/AnnotatedFactory.html +0 -8
  169. package/docs/static/typedoc/types/CloneAttachFunction.html +0 -2
  170. package/docs/static/typedoc/types/ControllerConstructor.html +0 -2
  171. package/docs/static/typedoc/types/DirectiveCompileFn.html +0 -2
  172. package/docs/static/typedoc/types/DirectiveController.html +0 -2
  173. package/docs/static/typedoc/types/DirectiveFactory.html +0 -1
  174. package/docs/static/typedoc/types/DirectiveFactoryFn.html +0 -1
  175. package/docs/static/typedoc/types/DirectiveLinkFn.html +0 -2
  176. package/docs/static/typedoc/types/ExpandoStore.html +0 -2
  177. package/docs/static/typedoc/types/FilterFactory.html +0 -2
  178. package/docs/static/typedoc/types/FilterFn.html +0 -2
  179. package/docs/static/typedoc/types/Injectable.html +0 -4
  180. package/docs/static/typedoc/types/InjectableClass.html +0 -1
  181. package/docs/static/typedoc/types/InjectableFactory.html +0 -1
  182. package/docs/static/typedoc/types/OnChangesObject.html +0 -2
  183. package/docs/static/typedoc/types/SwapModeType.html +0 -2
  184. package/docs/static/typedoc/types/TController.html +0 -2
  185. package/docs/static/typedoc/variables/SwapMode.html +0 -11
  186. package/src/filters/limit-to.md +0 -19
  187. package/src/filters/order-by.md +0 -83
  188. package/src/router/state/README.md +0 -21
  189. package/src/services/cookie-reader.js +0 -48
  190. package/src/services/http/http.md +0 -413
  191. package/src/services/http-backend/http-backend.js +0 -158
  192. package/src/services/http-backend/http-backend.spec.js +0 -389
  193. package/src/services/sce/sce.md +0 -300
  194. package/src/services/template-cache/interface.ts +0 -10
  195. /package/src/services/{anchor-scroll.html → anchor-scroll/anchor-scroll.html} +0 -0
@@ -1,389 +0,0 @@
1
- import { Angular } from "../../angular.js";
2
- import { createHttpBackend } from "./http-backend.js";
3
- import sinon from "sinon";
4
-
5
- describe("$httpBackend", () => {
6
- let $backend;
7
- let xhr;
8
- let callback;
9
- let requests;
10
- let angular;
11
-
12
- beforeEach(() => {
13
- xhr = sinon.useFakeXMLHttpRequest();
14
- requests = [];
15
- xhr.onCreate = function (req) {
16
- requests.push(req);
17
- };
18
- angular = window.angular = new Angular();
19
- $backend = createHttpBackend();
20
- callback = jasmine.createSpy("done");
21
- });
22
-
23
- afterEach(() => {
24
- xhr.restore();
25
- });
26
-
27
- it("should do basics - open async xhr and send data", () => {
28
- $backend("GET", "/some-url", "some-data", () => {});
29
- expect(requests.length).toBe(1);
30
- expect(requests[0].method).toBe("GET");
31
- expect(requests[0].url).toBe("/some-url");
32
- expect(requests[0].requestBody).toBe("some-data");
33
- expect(requests[0].async).toBe(true);
34
- });
35
-
36
- it("should pass null to send if no body is set", () => {
37
- $backend("GET", "/some-url", undefined, () => {});
38
- expect(requests[0].requestBody).toBe(null);
39
- });
40
-
41
- it("should pass the correct falsy value to send if falsy body is set (excluding undefined, NaN)", () => {
42
- [false, 0, "", null].forEach((value, index) => {
43
- $backend("GET", "/some-url", value, () => {});
44
- expect(requests[index].requestBody).toBe(value);
45
- });
46
- });
47
-
48
- it("should pass NaN to send if NaN body is set", () => {
49
- $backend("GET", "/some-url", NaN, () => {});
50
- expect(isNaN(requests[0].requestBody)).toEqual(true);
51
- });
52
-
53
- it("should call completion function with xhr.statusText if present", () => {
54
- callback.and.callFake((status, response, headers, statusText) => {
55
- expect(statusText).toBe("OK");
56
- });
57
-
58
- $backend("GET", "/some-url", null, callback);
59
- requests[0].respond(200);
60
- expect(callback).toHaveBeenCalled();
61
- });
62
-
63
- it("should set only the requested headers", () => {
64
- $backend("POST", "URL", null, () => {}, {
65
- "X-header1": "value1",
66
- "X-header2": "value2",
67
- });
68
- expect(requests[0].requestHeaders["X-header1"]).toEqual("value1");
69
- expect(requests[0].requestHeaders["X-header2"]).toEqual("value2");
70
- });
71
-
72
- it("should not try to read response data when request is aborted", () => {
73
- callback.and.callFake((status, response, headers, statusText) => {
74
- expect(status).toBe(-1);
75
- expect(response).toBe(null);
76
- expect(headers).toBe(null);
77
- expect(statusText).toBe("");
78
- });
79
- $backend("GET", "/url", null, callback, {}, 2000);
80
- requests[0].respond(0);
81
- expect(callback).toHaveBeenCalled();
82
- });
83
-
84
- it("should complete the request on abort", () => {
85
- callback.and.callFake(
86
- (status, response, headers, statusText, xhrStatus) => {
87
- expect(status).toBe(-1);
88
- expect(response).toBe(null);
89
- expect(headers).toBe(null);
90
- expect(statusText).toBe("");
91
- },
92
- );
93
- $backend("GET", "/url", null, callback, {});
94
-
95
- expect(callback).not.toHaveBeenCalled();
96
- requests[0].error();
97
- expect(callback).toHaveBeenCalled();
98
- });
99
-
100
- it("should complete the request on error", () => {
101
- callback.and.callFake(
102
- (status, response, headers, statusText, xhrStatus) => {
103
- expect(status).toBe(-1);
104
- expect(response).toBe(null);
105
- expect(headers).toBe(null);
106
- expect(statusText).toBe("");
107
- expect(xhrStatus).toBe("error");
108
- },
109
- );
110
- $backend("GET", "/url", null, callback, {});
111
-
112
- expect(callback).not.toHaveBeenCalled();
113
- requests[0].error();
114
- expect(callback).toHaveBeenCalled();
115
- });
116
-
117
- it("should complete the request on success", () => {
118
- callback.and.callFake(
119
- (status, response, headers, statusText, xhrStatus) => {
120
- expect(status).toBe(200);
121
- expect(response).toBe("response");
122
- expect(headers).toBe("");
123
- expect(statusText).toBe("OK");
124
- expect(xhrStatus).toBe("complete");
125
- },
126
- );
127
- $backend("GET", "/url", null, callback, {});
128
-
129
- expect(callback).not.toHaveBeenCalled();
130
- requests[0].respond(200, "", "response");
131
- expect(callback).toHaveBeenCalled();
132
- });
133
-
134
- // it("should set withCredentials", () => {
135
- // $backend("GET", "/some.url", null, callback, {}, null, true);
136
- // expect(requests[0].withCredentials).toBeTrue();
137
- // });
138
-
139
- // it("should abort request on $timeout promise resolution", () => {
140
- // callback.and.callFake(
141
- // (status, response, headers, statusText, xhrStatus) => {
142
- // expect(status).toBe(-1);
143
- // expect(xhrStatus).toBe("timeout");
144
- // },
145
- // );
146
-
147
- // $backend(
148
- // "GET",
149
- // "/url",
150
- // null,
151
- // callback,
152
- // {},
153
- // setTimeout(() => {}, 2000),
154
- // );
155
- // spyOn(xhr, "abort");
156
- // expect(xhr.abort).toHaveBeenCalled();
157
-
158
- // requests[0].abort();
159
- // expect(callback).toHaveBeenCalled();
160
- // });
161
-
162
- // it("should not abort resolved request on timeout promise resolution", () => {
163
- // callback.and.callFake((status, response) => {
164
- // expect(status).toBe(200);
165
- // });
166
-
167
- // $backend(
168
- // "GET",
169
- // "/url",
170
- // null,
171
- // callback,
172
- // {},
173
- // setTimeout(() => {}, 2000),
174
- // );
175
- // xhr = MockXhr.$$lastInstance;
176
- // spyOn(xhr, "abort");
177
-
178
- // xhr.status = 200;
179
- // xhr.onload();
180
- // expect(callback).toHaveBeenCalled();
181
-
182
- // $timeout.flush();
183
- // expect(xhr.abort).not.toHaveBeenCalled();
184
- // });
185
-
186
- // it("should abort request on canceler promise resolution", () => {
187
- // const canceler = Promise.withResolvers();
188
-
189
- // callback.and.callFake(
190
- // (status, response, headers, statusText, xhrStatus) => {
191
- // expect(status).toBe(-1);
192
- // expect(xhrStatus).toBe("abort");
193
- // },
194
- // );
195
-
196
- // $backend("GET", "/url", null, callback, {}, canceler.promise);
197
- // xhr = MockXhr.$$lastInstance;
198
-
199
- // canceler.resolve();
200
- // $browser.defer.flush();
201
-
202
- // expect(callback).toHaveBeenCalled();
203
- // });
204
-
205
- // it("should cancel timeout on completion", () => {
206
- // callback.and.callFake((status, response) => {
207
- // expect(status).toBe(200);
208
- // });
209
-
210
- // $backend("GET", "/url", null, callback, {}, 2000);
211
- // xhr = MockXhr.$$lastInstance;
212
- // spyOn(xhr, "abort");
213
-
214
- // expect($browser.deferredFns[0].time).toBe(2000);
215
-
216
- // xhr.status = 200;
217
- // xhr.onload();
218
- // expect(callback).toHaveBeenCalled();
219
-
220
- // expect($browser.deferredFns.length).toBe(0);
221
- // expect(xhr.abort).not.toHaveBeenCalled();
222
- // });
223
-
224
- // it('should call callback with xhrStatus "abort" on explicit xhr.abort() when $timeout is set', () => {
225
- // callback.and.callFake(
226
- // (status, response, headers, statusText, xhrStatus) => {
227
- // expect(status).toBe(-1);
228
- // expect(xhrStatus).toBe("abort");
229
- // },
230
- // );
231
-
232
- // $backend(
233
- // "GET",
234
- // "/url",
235
- // null,
236
- // callback,
237
- // {},
238
- // setTimeout(() => {}, 2000),
239
- // );
240
- // spyOn(xhr, "abort").and.callThrough();
241
-
242
- // xhr.abort();
243
-
244
- // expect(callback).toHaveBeenCalled();
245
- // });
246
-
247
- it("should set up event listeners", () => {
248
- const progressFn = function () {
249
- "progressFn";
250
- };
251
- $backend("GET", "/url", null, callback, {}, null, null, null, {
252
- progress: progressFn,
253
- });
254
- expect(requests[0].eventListeners.progress[1].listener).toBe(progressFn);
255
- //expect(requests[0].eventListeners.progress[1].listener).toBe(uploadProgressFn);
256
- });
257
-
258
- // describe("responseType", () => {
259
- // it("should set responseType and return xhr.response", () => {
260
- // $backend("GET", "/whatever", null, callback, {}, null, null, "blob");
261
-
262
- // const xhrInstance = MockXhr.$$lastInstance;
263
- // expect(xhrInstance.responseType).toBe("blob");
264
-
265
- // callback.and.callFake((status, response) => {
266
- // expect(response).toBe(xhrInstance.response);
267
- // });
268
-
269
- // xhrInstance.response = { some: "object" };
270
- // xhrInstance.onload();
271
-
272
- // expect(callback).toHaveBeenCalled();
273
- // });
274
-
275
- // it("should read responseText if response was not defined", () => {
276
- // // old browsers like IE9, don't support responseType, so they always respond with responseText
277
-
278
- // $backend("GET", "/whatever", null, callback, {}, null, null, "blob");
279
-
280
- // const xhrInstance = MockXhr.$$lastInstance;
281
- // const responseText = '{"some": "object"}';
282
- // expect(xhrInstance.responseType).toBe("blob");
283
-
284
- // callback.and.callFake((status, response) => {
285
- // expect(response).toBe(responseText);
286
- // });
287
-
288
- // xhrInstance.responseText = responseText;
289
- // xhrInstance.onload();
290
-
291
- // expect(callback).toHaveBeenCalled();
292
- // });
293
- // });
294
-
295
- // describe("protocols that return 0 status code", () => {
296
- // function respond(status, content) {
297
- // xhr = MockXhr.$$lastInstance;
298
- // xhr.status = status;
299
- // xhr.responseText = content;
300
- // xhr.onload();
301
- // }
302
-
303
- // beforeEach(() => {
304
- // $backend = createHttpBackend($browser, createMockXhr);
305
- // });
306
-
307
- // it("should convert 0 to 200 if content and file protocol", () => {
308
- // $backend("GET", "file:///whatever/index.html", null, callback);
309
- // respond(0, "SOME CONTENT");
310
-
311
- // expect(callback).toHaveBeenCalled();
312
- // expect(callback.calls.mostRecent().args[0]).toBe(200);
313
- // });
314
-
315
- // it("should convert 0 to 200 if content for protocols other than file", () => {
316
- // $backend("GET", "someProtocol:///whatever/index.html", null, callback);
317
- // respond(0, "SOME CONTENT");
318
-
319
- // expect(callback).toHaveBeenCalled();
320
- // expect(callback.calls.mostRecent().args[0]).toBe(200);
321
- // });
322
-
323
- // it("should convert 0 to 404 if no content and file protocol", () => {
324
- // $backend("GET", "file:///whatever/index.html", null, callback);
325
- // respond(0, "");
326
-
327
- // expect(callback).toHaveBeenCalled();
328
- // expect(callback.calls.mostRecent().args[0]).toBe(404);
329
- // });
330
-
331
- // it("should not convert 0 to 404 if no content for protocols other than file", () => {
332
- // $backend("GET", "someProtocol:///whatever/index.html", null, callback);
333
- // respond(0, "");
334
-
335
- // expect(callback).toHaveBeenCalled();
336
- // expect(callback.calls.mostRecent().args[0]).toBe(0);
337
- // });
338
-
339
- // it("should convert 0 to 404 if no content - relative url", () => {
340
- // const originalUrlParsingNode = urlParsingNode;
341
-
342
- // // temporarily overriding the DOM element to pretend that the test runs origin with file:// protocol
343
- // urlParsingNode = {
344
- // hash: "#/C:/",
345
- // host: "",
346
- // hostname: "",
347
- // href: "file:///C:/base#!/C:/foo",
348
- // pathname: "/C:/foo",
349
- // port: "",
350
- // protocol: "file:",
351
- // search: "",
352
- // setAttribute: () => {},
353
- // };
354
-
355
- // try {
356
- // $backend("GET", "/whatever/index.html", null, callback);
357
- // respond(0, "");
358
-
359
- // expect(callback).toHaveBeenCalled();
360
- // expect(callback.calls.mostRecent().args[0]).toBe(404);
361
- // } finally {
362
- // urlParsingNode = originalUrlParsingNode;
363
- // }
364
- // });
365
-
366
- // it("should return original backend status code if different from 0", () => {
367
- // // request to http://
368
- // $backend("POST", "http://rest_api/create_whatever", null, callback);
369
- // respond(201, "");
370
-
371
- // expect(callback).toHaveBeenCalled();
372
- // expect(callback.calls.mostRecent().args[0]).toBe(201);
373
-
374
- // // request to file://
375
- // $backend("POST", "file://rest_api/create_whatever", null, callback);
376
- // respond(201, "");
377
-
378
- // expect(callback).toHaveBeenCalled();
379
- // expect(callback.calls.mostRecent().args[0]).toBe(201);
380
-
381
- // // request to file:// with HTTP status >= 300
382
- // $backend("POST", "file://rest_api/create_whatever", null, callback);
383
- // respond(503, "");
384
-
385
- // expect(callback).toHaveBeenCalled();
386
- // expect(callback.calls.mostRecent().args[0]).toBe(503);
387
- // });
388
- // });
389
- });
@@ -1,300 +0,0 @@
1
- /\*\*
2
-
3
- - The $sceProvider provider allows developers to configure the {@link ng.$sce $sce} service.
4
- - - enable/disable Strict Contextual Escaping (SCE) in a module
5
- - - override the default implementation with a custom delegate
6
- -
7
- - Read more about {@link ng.$sce Strict Contextual Escaping (SCE)}.
8
- \*/
9
-
10
- /\*\*
11
-
12
- -
13
- - `$sce` is a service that provides Strict Contextual Escaping services to AngularTS.
14
- -
15
- - ## Strict Contextual Escaping
16
- -
17
- - Strict Contextual Escaping (SCE) is a mode in which AngularTS constrains bindings to only render
18
- - trusted values. Its goal is to assist in writing code in a way that (a) is secure by default, and
19
- - (b) makes auditing for security vulnerabilities such as XSS, clickjacking, etc. a lot easier.
20
- -
21
- - ### Overview
22
- -
23
- - To systematically block XSS security bugs, AngularTS treats all values as untrusted by default in
24
- - HTML or sensitive URL bindings. When binding untrusted values, AngularTS will automatically
25
- - run security checks on them (sanitizations, trusted URL resource, depending on context), or throw
26
- - when it cannot guarantee the security of the result. That behavior depends strongly on contexts:
27
- - HTML can be sanitized, but template URLs cannot, for instance.
28
- -
29
- - To illustrate this, consider the `ng-bind-html` directive. It renders its value directly as HTML:
30
- - we call that the _context_. When given an untrusted input, AngularTS will attempt to sanitize it
31
- - before rendering if a sanitizer is available, and throw otherwise. To bypass sanitization and
32
- - render the input as-is, you will need to mark it as trusted for that context before attempting
33
- - to bind it.
34
- -
35
- - As of version 1.2, AngularTS ships with SCE enabled by default.
36
- -
37
- - ### In practice
38
- -
39
- - Here's an example of a binding in a privileged context:
40
- -
41
- - ```
42
-
43
- ```
44
-
45
- - <input ng-model="userHtml" aria-label="User input">
46
- - <div ng-bind-html="userHtml"></div>
47
- - ```
48
-
49
- ```
50
-
51
- -
52
- - Notice that `ng-bind-html` is bound to `userHtml` controlled by the user. With SCE
53
- - disabled, this application allows the user to render arbitrary HTML into the DIV, which would
54
- - be an XSS security bug. In a more realistic example, one may be rendering user comments, blog
55
- - articles, etc. via bindings. (HTML is just one example of a context where rendering user
56
- - controlled input creates security vulnerabilities.)
57
- -
58
- - For the case of HTML, you might use a library, either on the client side, or on the server side,
59
- - to sanitize unsafe HTML before binding to the value and rendering it in the document.
60
- -
61
- - How would you ensure that every place that used these types of bindings was bound to a value that
62
- - was sanitized by your library (or returned as safe for rendering by your server?) How can you
63
- - ensure that you didn't accidentally delete the line that sanitized the value, or renamed some
64
- - properties/fields and forgot to update the binding to the sanitized value?
65
- -
66
- - To be secure by default, AngularTS makes sure bindings go through that sanitization, or
67
- - any similar validation process, unless there's a good reason to trust the given value in this
68
- - context. That trust is formalized with a function call. This means that as a developer, you
69
- - can assume all untrusted bindings are safe. Then, to audit your code for binding security issues,
70
- - you just need to ensure the values you mark as trusted indeed are safe - because they were
71
- - received from your server, sanitized by your library, etc. You can organize your codebase to
72
- - help with this - perhaps allowing only the files in a specific directory to do this.
73
- - Ensuring that the internal API exposed by that code doesn't markup arbitrary values as safe then
74
- - becomes a more manageable task.
75
- -
76
- - In the case of AngularTS' SCE service, one uses {@link ng.$sce#trustAs $sce.trustAs}
77
- - (and shorthand methods such as {@link ng.$sce#trustAsHtml $sce.trustAsHtml}, etc.) to
78
- - build the trusted versions of your values.
79
- -
80
- - ### How does it work?
81
- -
82
- - In privileged contexts, directives and code will bind to the result of {@link ng.$sce#getTrusted
83
- - $sce.getTrusted(context, value)} rather than to the value directly. Think of this function as
84
- - a way to enforce the required security context in your data sink. Directives use {@link
85
- - ng.$sceparseAs $sce.parseAs} rather than `$parse` to watch attribute bindings, which performs
86
- - the {@link ng.$sce#getTrusted $sce.getTrusted} behind the scenes on non-constant literals. Also,
87
- - when binding without directives, AngularTS will understand the context of your bindings
88
- - automatically.
89
- -
90
- - As an example, {@link ng.directive:ngBindHtml ngBindHtml} uses {@link
91
- - ng.$sceparseAsHtml $sce.parseAsHtml(binding expression)}. Here's the actual code (slightly
92
- - simplified):
93
- -
94
- - ```
95
-
96
- ```
97
-
98
- - let ngBindHtmlDirective = ['$sce', function($sce) {
99
- - return function(scope, element, attr) {
100
- - scope.$watch($sce.parseAsHtml(attr.ngBindHtml), function(value) {
101
- - element.html(value || '');
102
- - });
103
- - };
104
- - }];
105
- - ```
106
-
107
- ```
108
-
109
- -
110
- - ### Impact on loading templates
111
- -
112
- - This applies both to the {@link ng.directive:ngInclude `ng-include`} directive as well as
113
- - `templateUrl`'s specified by {@link guide/directive directives}.
114
- -
115
- - By default, AngularTS only loads templates from the same domain and protocol as the application
116
- - document. This is done by calling {@link ng.$sce#getTrustedResourceUrl
117
- - $sce.getTrustedResourceUrl} on the template URL. To load templates from other domains and/or
118
- - protocols, you may either add them to the {@link ng.$sceDelegateProvider#trustedResourceUrlList
119
- - trustedResourceUrlList} or {@link ng.$sce#trustAsResourceUrl wrap them} into trusted values.
120
- -
121
- - _Please note_:
122
- - The browser's
123
- - [Same Origin Policy](https://code.google.com/p/browsersec/wiki/Part2#Same-origin_policy_for_XMLHttpRequest)
124
- - and [Cross-Origin Resource Sharing (CORS)](http://www.w3.org/TR/cors/)
125
- - policy apply in addition to this and may further restrict whether the template is successfully
126
- - loaded. This means that without the right CORS policy, loading templates from a different domain
127
- - won't work on all browsers. Also, loading templates from `file://` URL does not work on some
128
- - browsers.
129
- -
130
- - ### This feels like too much overhead
131
- -
132
- - It's important to remember that SCE only applies to interpolation expressions.
133
- -
134
- - If your expressions are constant literals, they're automatically trusted and you don't need to
135
- - call `$sce.trustAs` on them (e.g.
136
- - `<div ng-bind-html="'<b>implicitly trusted</b>'"></div>`) just works (remember to include the
137
- - `ngSanitize` module). The `$sceDelegate` will also use the `$sanitize` service if it is available
138
- - when binding untrusted values to `$sce.HTML` context.
139
- - AngularTS provides an implementation in `angular-sanitize.js`, and if you
140
- - wish to use it, you will also need to depend on the {@link ngSanitize `ngSanitize`} module in
141
- - your application.
142
- -
143
- - The included {@link ng.$sceDelegate $sceDelegate} comes with sane defaults to allow you to load
144
- - templates in `ng-include` from your application's domain without having to even know about SCE.
145
- - It blocks loading templates from other domains or loading templates over http from an https
146
- - served document. You can change these by setting your own custom {@link
147
- - ng.$sceDelegateProvider#trustedResourceUrlList trusted resource URL list} and {@link
148
- - ng.$sceDelegateProvider#bannedResourceUrlList banned resource URL list} for matching such URLs.
149
- -
150
- - This significantly reduces the overhead. It is far easier to pay the small overhead and have an
151
- - application that's secure and can be audited to verify that with much more ease than bolting
152
- - security onto an application later.
153
- -
154
- - <a name="contexts"></a>
155
- - ### What trusted context types are supported?
156
- -
157
- - | Context | Notes |
158
- - |---------------------|----------------|
159
- - | `$sce.HTML` | For HTML that's safe to source into the application. The {@link ng.directive:ngBindHtml ngBindHtml} directive uses this context for bindings. If an unsafe value is encountered and the {@link ngSanitize $sanitize} module is present this will sanitize the value instead of throwing an error. |
160
- - | `$sce.CSS` | For CSS that's safe to source into the application. Currently unused. Feel free to use it in your own directives. |
161
- - | `$sce.MEDIA_URL` | For URLs that are safe to render as media. Is automatically converted from string by sanitizing when needed. |
162
- - | `$sce.URL` | For URLs that are safe to follow as links. Is automatically converted from string by sanitizing when needed. Note that `$sce.URL` makes a stronger statement about the URL than `$sce.MEDIA_URL` does and therefore contexts requiring values trusted for `$sce.URL` can be used anywhere that values trusted for `$sce.MEDIA_URL` are required.|
163
- - | `$sce.RESOURCE_URL` | For URLs that are not only safe to follow as links, but whose contents are also safe to include in your application. Examples include `ng-include`, `src` / `ngSrc` bindings for tags other than `IMG` (e.g. `IFRAME`, `OBJECT`, etc.) <br><br>Note that `$sce.RESOURCE_URL` makes a stronger statement about the URL than `$sce.URL` or `$sce.MEDIA_URL` do and therefore contexts requiring values trusted for `$sce.RESOURCE_URL` can be used anywhere that values trusted for `$sce.URL` or `$sce.MEDIA_URL` are required. <br><br> The {@link $sceDelegateProvider#trustedResourceUrlList $sceDelegateProvider#trustedResourceUrlList()} and {@link $sceDelegateProvider#bannedResourceUrlList $sceDelegateProvider#bannedResourceUrlList()} can be used to restrict trusted origins for `RESOURCE_URL` |
164
- - | `$sce.JS` | For JavaScript that is safe to execute in your application's context. Currently unused. Feel free to use it in your own directives. |
165
- -
166
- -
167
- - <div class="alert alert-warning">
168
- - Be aware that, before AngularTS 1.7.0, `a[href]` and `img[src]` used to sanitize their
169
- - interpolated values directly rather than rely upon {@link ng.$sce#getTrusted `$sce.getTrusted`}.
170
- -
171
- - **As of 1.7.0, this is no longer the case.**
172
- -
173
- - Now such interpolations are marked as requiring `$sce.URL` (for `a[href]`) or `$sce.MEDIA_URL`
174
- - (for `img[src]`), so that the sanitization happens (via `$sce.getTrusted...`) when the `$interpolate`
175
- - service evaluates the expressions.
176
- - </div>
177
- -
178
- - There are no CSS or JS context bindings in AngularTS currently, so their corresponding `$sce.trustAs`
179
- - functions aren't useful yet. This might evolve.
180
- -
181
- - ### Format of items in {@link ng.$sceDelegateProvider#trustedResourceUrlList trustedResourceUrlList}/{@link ng.$sceDelegateProvider#bannedResourceUrlList bannedResourceUrlList} <a name="resourceUrlPatternItem"></a>
182
- -
183
- - Each element in these arrays must be one of the following:
184
- -
185
- - - **'self'**
186
- - - The special **string**, `'self'`, can be used to match against all URLs of the \*\*same
187
- - domain** as the application document using the **same protocol**.
188
- - - **String** (except the special value `'self'`)
189
- - - The string is matched against the full _normalized / absolute URL_ of the resource
190
- - being tested (substring matches are not good enough.)
191
- - - There are exactly **two wildcard sequences** - `*` and `**`. All other characters
192
- - match themselves.
193
- - - `*`: matches zero or more occurrences of any character other than one of the following 6
194
- - characters: '`:`', '`/`', '`.`', '`?`', '`&`' and '`;`'. It's a useful wildcard for use
195
- - for matching resource URL lists.
196
- - - `**`: matches zero or more occurrences of _any_ character. As such, it's not
197
- - appropriate for use in a scheme, domain, etc. as it would match too much. (e.g.
198
- - http://**.example.com/ would match http://evil.com/?ignore=.example.com/ and that might
199
- - not have been the intention.) Its usage at the very end of the path is ok. (e.g.
200
- - http://foo.example.com/templates/**).
201
- - - **RegExp** (_see caveat below_)
202
- - - _Caveat_: While regular expressions are powerful and offer great flexibility, their syntax
203
- - (and all the inevitable escaping) makes them *harder to maintain*. It's easy to
204
- - accidentally introduce a bug when one updates a complex expression (imho, all regexes should
205
- - have good test coverage). For instance, the use of `.` in the regex is correct only in a
206
- - small number of cases. A `.` character in the regex used when matching the scheme or a
207
- - subdomain could be matched against a `:` or literal `.` that was likely not intended. It
208
- - is highly recommended to use the string patterns and only fall back to regular expressions
209
- - as a last resort.
210
- - - The regular expression must be an instance of RegExp (i.e. not a string.) It is
211
- - matched against the **entire** *normalized / absolute URL* of the resource being tested
212
- - (even when the RegExp did not have the `^` and `$` codes.) In addition, any flags
213
- - present on the RegExp (such as multiline, global, ignoreCase) are ignored.
214
- - - If you are generating your JavaScript from some other templating engine (not
215
- - recommended, e.g. in issue [#4006](https://github.com/angular/angular.js/issues/4006)),
216
- - remember to escape your regular expression (and be aware that you might need more than
217
- - one level of escaping depending on your templating engine and the way you interpolated
218
- - the value.) Do make use of your platform's escaping mechanism as it might be good
219
- - enough before coding your own. E.g. Ruby has
220
- - [Regexp.escape(str)](http://www.ruby-doc.org/core-2.0.0/Regexp.html#method-c-escape)
221
- - and Python has [re.escape](http://docs.python.org/library/re.html#re.escape).
222
- - Javascript lacks a similar built in function for escaping. Take a look at Google
223
- - Closure library's [goog.string.regExpEscape(s)](
224
- - http://docs.closure-library.googlecode.com/git/closure_goog_string_string.js.source.html#line962).
225
- -
226
- - Refer {@link ng.$sceDelegateProvider $sceDelegateProvider} for an example.
227
- -
228
- -
229
- - ## Can I disable SCE completely?
230
- -
231
- - Yes, you can. However, this is strongly discouraged. SCE gives you a lot of security beneits
232
- - for little coding overhead. It will be much harder to take an SCE disabled application and
233
- - either secure it on your own or enable SCE at a later stage. It might make sense to disable SCE
234
- - for cases where you have a lot of existing code that was written before SCE was introduced and
235
- - you're migrating them a module at a time. Also do note that this is an app-wide setting, so if
236
- - you are writing a library, you will cause security bugs applications using it.
237
- -
238
- - That said, here's how you can completely disable SCE:
239
- -
240
- - ```
241
-
242
- ```
243
-
244
- - angular.module('myAppWithSceDisabledmyApp', []).config(function($sceProvider) {
245
- - // Completely disable SCE. For demonstration purposes only!
246
- - // Do not use in new projects or libraries.
247
- - $sceProvider.enabled(false);
248
- - });
249
- - ```
250
-
251
- ```
252
-
253
- - \*/
254
-
255
- /\* Design notes on the default implementation for SCE.
256
-
257
- -
258
- - The API contract for the SCE delegate
259
- - ***
260
- - The SCE delegate object must provide the following 3 methods:
261
- -
262
- - - trustAs(contextEnum, value)
263
- - This method is used to tell the SCE service that the provided value is OK to use in the
264
- - contexts specified by contextEnum. It must return an object that will be accepted by
265
- - getTrusted() for a compatible contextEnum and return this value.
266
- -
267
- - - valueOf(value)
268
- - For values that were not produced by trustAs(), return them as is. For values that were
269
- - produced by trustAs(), return the corresponding input value to trustAs. Basically, if
270
- - trustAs is wrapping the given values into some type, this operation unwraps it when given
271
- - such a value.
272
- -
273
- - - getTrusted(contextEnum, value)
274
- - This function should return the value that is safe to use in the context specified by
275
- - contextEnum or throw and exception otherwise.
276
- -
277
- - NOTE: This contract deliberately does NOT state that values returned by trustAs() must be
278
- - opaque or wrapped in some holder object. That happens to be an implementation detail. For
279
- - instance, an implementation could maintain a registry of all trusted objects by context. In
280
- - such a case, trustAs() would return the same object that was passed in. getTrusted() would
281
- - return the same object passed in if it was found in the registry under a compatible context or
282
- - throw an exception otherwise. An implementation might only wrap values some of the time based
283
- - on some criteria. getTrusted() might return a value and not throw an exception for special
284
- - constants or objects even if not wrapped. All such implementations fulfill this contract.
285
- -
286
- -
287
- - A note on the inheritance model for SCE contexts
288
- - ***
289
- - I've used inheritance and made RESOURCE_URL wrapped types a subtype of URL wrapped types. This
290
- - is purely an implementation details.
291
- -
292
- - The contract is simply this:
293
- -
294
- - getTrusted($sce.RESOURCE_URL, value) succeeding implies that getTrusted($sce.URL, value)
295
- - will also succeed.
296
- -
297
- - Inheritance happens to capture this in a natural way. In some future, we may not use
298
- - inheritance anymore. That is OK because no code outside of sce.js and sceSpecs.js would need to
299
- - be aware of this detail.
300
- \*/