Skip to content

Commit 11d6035

Browse files
committed
Windows OS compatibility test 1
1 parent 644ac55 commit 11d6035

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

javascript/frameworks/cap/lib/advanced_security/javascript/frameworks/cap/Application.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@ class RootDirectory extends Folder {
1212

1313
/**
1414
* Gets the path of a file relative to this root directory.
15+
*
16+
* Note: On Windows, `getAbsolutePath()` returns backslash-separated paths.
17+
* We normalize backslashes to forward slashes before comparison to ensure
18+
* cross-platform compatibility.
1519
*/
1620
string getFilePathRelativeToRoot(File file) {
17-
result = file.getAbsolutePath().regexpReplaceAll(this.getAbsolutePath(), ".") and
21+
result =
22+
file.getAbsolutePath()
23+
.replaceAll("\\", "/")
24+
.regexpReplaceAll(this.getAbsolutePath().replaceAll("\\", "/"), ".") and
1825
result.charAt(0) = "."
1926
}
2027

javascript/frameworks/cap/lib/advanced_security/javascript/frameworks/cap/CDL.qll

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ abstract class CdlObject extends JsonObject {
2020
// performed and `.cds.json` files are stored in that base project directory. The
2121
// `$location` values in the generated JSON data are, therefore, relative to the
2222
// base directory of the project.
23+
//
24+
// Note: On Windows, `getAbsolutePath()` returns backslash-separated paths, but
25+
// `$location.file` values in `.cds.json` always use forward slashes (POSIX).
26+
// We normalize backslashes to forward slashes to ensure cross-platform compatibility.
2327
path =
24-
locValue.getJsonFile().getParentContainer().getAbsolutePath().regexpReplaceAll("/$", "") +
25-
"/" + locValue.getPropValue("file").getStringValue() and
28+
locValue
29+
.getJsonFile()
30+
.getParentContainer()
31+
.getAbsolutePath()
32+
.replaceAll("\\", "/")
33+
.regexpReplaceAll("/$", "") + "/" + locValue.getPropValue("file").getStringValue() and
2634
if
2735
not exists(locValue.getPropValue("line")) and
2836
not exists(locValue.getPropValue("col"))
@@ -167,11 +175,15 @@ class CdlService extends CdlElement {
167175
exists(JsonValue jsonFileLocation |
168176
jsonFileLocation = this.getPropValue("$location").getPropValue("file")
169177
|
170-
result.getFile().getAbsolutePath().regexpReplaceAll("\\.[^.]+$", ".cds") =
178+
// Normalize backslashes to forward slashes for cross-platform compatibility.
179+
// On Windows, `getAbsolutePath()` returns backslash-separated paths, but
180+
// `$location.file` values in `.cds.json` always use forward slashes (POSIX).
181+
result.getFile().getAbsolutePath().replaceAll("\\", "/").regexpReplaceAll("\\.[^.]+$", ".cds") =
171182
jsonFileLocation
172183
.getJsonFile()
173184
.getParentContainer()
174185
.getAbsolutePath()
186+
.replaceAll("\\", "/")
175187
.regexpReplaceAll("/$", "") + "/" + jsonFileLocation.getStringValue()
176188
)
177189
}

javascript/frameworks/cap/lib/advanced_security/javascript/frameworks/cap/PackageJson.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class RequiredService extends JsonObject {
4242

4343
File getImplementationFile() {
4444
exists(RootDirectory root |
45+
// `getFilePathRelativeToRoot` now returns normalized forward-slash paths,
46+
// matching the forward-slash convention used in package.json `impl` values.
4547
root.getFilePathRelativeToRoot(result) = "./" + this.getPropStringValue("impl")
4648
)
4749
}

0 commit comments

Comments
 (0)