Skip to content

Commit 824054b

Browse files
committed
JS: Change note and updated help
1 parent 7091a9f commit 824054b

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

change-notes/1.25/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
| Hard-coded credentials (`js/hardcoded-credentials`) | More results | This query now recognizes hard-coded credentials sent via HTTP authorization headers. |
4747
| Incomplete URL scheme check (`js/incomplete-url-scheme-check`) | More results | This query now recognizes additional url scheme checks. |
4848
| Misspelled variable name (`js/misspelled-variable-name`) | Message changed | The message for this query now correctly identifies the misspelled variable in additional cases. |
49+
| Non-linear pattern (`js/non-linear-pattern`) | Fewer duplicates and message changed | This query now generates fewer duplicate alerts and has a clearer explanation in case of type annotations used in a pattern. |
4950
| Prototype pollution in utility function (`js/prototype-pollution-utility`) | More results | This query now recognizes additional utility functions as vulnerable to prototype polution. |
5051
| Uncontrolled command line (`js/command-line-injection`) | More results | This query now recognizes additional command execution calls. |
5152
| Uncontrolled data used in path expression (`js/path-injection`) | More results | This query now recognizes additional file system calls. |

javascript/ql/src/LanguageFeatures/NonLinearPattern.qhelp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ If the same pattern variable is bound multiple times in the same object or array
88
binding overwrites all of the earlier ones. This is most likely unintended and should be avoided.
99
</p>
1010

11+
<p>
12+
In TypeScript, a common mistake is to try to write type annotations inside a pattern. This is not
13+
possible, and the type annotation should come after the pattern.
14+
</p>
15+
1116
</overview>
1217
<recommendation>
1318

@@ -34,6 +39,21 @@ From context, it appears that the second binding should have been for variable <
3439

3540
<sample src="examples/NonLinearPatternGood.js" />
3641

42+
<p>
43+
This can sometimes happen in TypeScript, due to the apparant similarity between property patterns
44+
and type annotations. In the following example, the function uses a pattern parameter with properties <code>x</code>
45+
and <code>y</code>. These appear to have type <code>number</code>, but are in fact untyped properties both stored in a variable named <code>number</code>.
46+
</p>
47+
48+
<sample src="examples/NonLinearPatternTS.ts" />
49+
50+
<p>
51+
It is not possible to specify type annotations inside a pattern. The correct way is to specify the type
52+
after the parameter:
53+
</p>
54+
55+
<sample src="examples/NonLinearPatternTSGood.ts" />
56+
3757
</example>
3858
<references>
3959
<li>Mozilla Developer Network: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment">Destructuring assignment</a>.</li>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function distance({x: number, y: number}) {
2+
return Math.sqrt(x*x + y*y);
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function distance({x, y}: {x: number, y: number}) {
2+
return Math.sqrt(x*x + y*y);
3+
}

0 commit comments

Comments
 (0)