Skip to content

Commit 8bd3113

Browse files
Copilotsergey-tihon
andcommitted
Refactor relative path checking logic to remove redundancy
- Extract startsWithRelativeMarker helper function to avoid code duplication - Remove redundant checks after path normalization - Both Windows and Unix platforms now use the same helper for consistency Co-authored-by: sergey-tihon <[email protected]>
1 parent 88626a5 commit 8bd3113

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/SwaggerProvider.DesignTime/Utils.fs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ module SchemaReader =
77
open System.Net.Http
88
open System.Runtime.InteropServices
99

10+
/// Checks if a path starts with relative markers like ../ or ./
11+
let private startsWithRelativeMarker(path: string) =
12+
let normalized = path.Replace('\\', '/')
13+
normalized.StartsWith("/../") || normalized.StartsWith("/./")
14+
1015
/// Determines if a path is truly absolute (not just rooted)
1116
/// On Windows: C:\path is absolute, \path is rooted (combine with drive), but \..\path is relative
1217
/// On Unix: /path is absolute, but /../path or /./path are relative
@@ -26,20 +31,12 @@ module SchemaReader =
2631
true
2732
else
2833
// Rooted but no drive - check if it starts with relative markers
29-
// \..\ or /../ or /..\ etc. are relative, not absolute
30-
// \.\ or /./ or /\ etc. are also relative
31-
let normalized = path.Replace('\\', '/')
32-
33-
not(
34-
normalized.StartsWith("/../")
35-
|| normalized.StartsWith("/./")
36-
|| normalized.StartsWith("/..\\")
37-
|| normalized.StartsWith("/.\\")
38-
)
34+
// \..\ or /../ are relative, not absolute
35+
not(startsWithRelativeMarker path)
3936
else
4037
// On Unix, a rooted path is absolute if it starts with /
4138
// BUT: if the path starts with /../ or /./, it's relative
42-
root = "/" && not(path.StartsWith("/../") || path.StartsWith("/./"))
39+
root = "/" && not(startsWithRelativeMarker path)
4340

4441
let getAbsolutePath (resolutionFolder: string) (schemaPathRaw: string) =
4542
if String.IsNullOrWhiteSpace(schemaPathRaw) then

0 commit comments

Comments
 (0)