- Notifications
You must be signed in to change notification settings - Fork20.6k
Commitda74354
committed
Manipulation: Avoid concatenating strings in buildFragment
Concatenating HTML strings in buildFragment is a possible security risk as itcreates an opportunity of escaping the concatenated wrapper. It also makes itimpossible to support secure HTML wrappers like[trusted types](https://web.dev/trusted-types/). It's safer to create wrapperelements using `document.createElement` & `appendChild`.The previous way was needed in jQuery <4 because IE <10 doesn't accept tableparts set via `innerHTML`, even if the element which contents are set isa proper table element, e.g.:```jstr.innerHTML = "<td></td>";```The whole structure needs to be passed in one HTML string. jQuery 4 dropssupport for IE <11 so this is no longer an issue; in older version we'd have toduplicate the code paths.IE <10 needed to have `<option>` elements wrapped in`<select multiple="multiple">` but we no longer need that on master which makesthe `document.createElement` way shorter as we don't have to call`setAttribute`.jQuery 1.x sometimes needed to have more than one element in the wrapper thatwould precede parts wrapping HTML input so descending needed to use `lastChild`.Since all wrappers are single-element now, we can use `firstChild` whichcompresses better as it's used in other places in the code as well.All these improvements, apart from making logic more secure, decrease thegzipped size by 55 bytes.Refgh-4409Refangular/angular.js#170281 parent0b676ae commitda74354
File tree
3 files changed
+25
-13
lines changed- src/manipulation
- test/unit
3 files changed
+25
-13
lines changedLines changed: 10 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | 1 |
| |
2 | 2 |
| |
3 | 3 |
| |
| 4 | + | |
| 5 | + | |
4 | 6 |
| |
5 | 7 |
| |
6 | 8 |
| |
| |||
35 | 37 |
| |
36 | 38 |
| |
37 | 39 |
| |
38 |
| - | |
39 |
| - | |
| 40 | + | |
40 | 41 |
| |
41 |
| - | |
42 |
| - | |
43 |
| - | |
44 |
| - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
45 | 47 |
| |
46 | 48 |
| |
| 49 | + | |
| 50 | + | |
47 | 51 |
| |
48 | 52 |
| |
49 | 53 |
| |
|
Lines changed: 4 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 |
| - | |
2 | 1 |
| |
3 | 2 |
| |
4 | 3 |
| |
5 | 4 |
| |
6 | 5 |
| |
7 | 6 |
| |
8 | 7 |
| |
9 |
| - | |
10 |
| - | |
11 |
| - | |
12 |
| - | |
13 |
| - | |
14 |
| - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
15 | 12 |
| |
16 | 13 |
| |
17 | 14 |
| |
|
Lines changed: 11 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2969 | 2969 |
| |
2970 | 2970 |
| |
2971 | 2971 |
| |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + |
0 commit comments
Comments
(0)