Skip to content

Commit aade79f

Browse files
Improve qldoc and fix changenote
1 parent 9097d93 commit aade79f

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1+
---
12
category: feature
23
---
3-
* Added `FilePath` API for normalizing filepaths.
4-
```
4+
* Added `FilePath` API for normalizing filepaths.

shared/util/codeql/util/FilePath.qll

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ abstract class NormalizableFilepath extends string {
88
bindingset[this]
99
NormalizableFilepath() { any() }
1010

11+
/** Gets the `i`th path component of this string. */
1112
private string getComponent(int i) { result = this.splitAt("/", i) }
1213

14+
/** Gets the number of path components of thi string. */
1315
private int getNumComponents() { result = strictcount(int i | exists(this.getComponent(i))) }
1416

15-
/** count .. segments in prefix in normalization from index i */
17+
/** In the normalized path starting from component `i`, counts the number of `..` segments that path starts with. */
1618
private int dotdotCountFrom(int i) {
1719
result = 0 and i = this.getNumComponents()
1820
or
@@ -29,7 +31,7 @@ abstract class NormalizableFilepath extends string {
2931
)
3032
}
3133

32-
/** count non-.. segments in postfix in normalization from index 0 to i-1 */
34+
/** In the normalized path up to (excluding) component `i`, counts the number of non-`..` segments that path ends with. */
3335
private int segmentCountUntil(int i) {
3436
result = 0 and i = 0
3537
or
@@ -46,6 +48,7 @@ abstract class NormalizableFilepath extends string {
4648
)
4749
}
4850

51+
/** Gets the `i`th component if that component should be included in the normalized path. */
4952
private string part(int i) {
5053
result = this.getComponent(i) and
5154
result != "." and
@@ -60,7 +63,13 @@ abstract class NormalizableFilepath extends string {
6063
)
6164
}
6265

63-
/** Gets the normalized filepath for this string; traversing `/../` paths. */
66+
/**
67+
* Gets the normalized filepath for this string.
68+
* Normalizes `..` paths, `.` paths, and multiple `/`s as much as possible, but does not normalize case, resolve symlinks, or make relative paths absolute.
69+
* Th normalized path will be absolute (begin with `/`) if and only if the original path is.
70+
* The normalized path will not have a trailing `/`.
71+
* Only `/` is treated as a path separator.
72+
*/
6473
string getNormalizedPath() {
6574
exists(string norm | norm = concat(string s, int i | s = this.part(i) | s, "/" order by i) |
6675
if norm != ""

0 commit comments

Comments
 (0)