|
2 | 2 |
|
3 | 3 | import csharp
|
4 | 4 | private import codeql.util.Unit
|
| 5 | +private import codeql.util.FilePath |
5 | 6 | private import semmle.code.csharp.frameworks.microsoft.AspNetCore
|
6 | 7 |
|
7 | 8 | /**
|
@@ -179,45 +180,3 @@ private class RelativeViewCallFilepath extends NormalizableFilepath {
|
179 | 180 | /** Holds if this string is the `idx`th path that will be searched for the `vc` call. */
|
180 | 181 | predicate hasViewCallWithIndex(ViewCall vc, int idx) { vc = vc_ and idx = idx_ }
|
181 | 182 | }
|
182 |
| - |
183 |
| -// TODO: this could be a shared library |
184 |
| -/** |
185 |
| - * A filepath that should be normalized. |
186 |
| - * Extend to provide additional strings that should be normalized as filepaths. |
187 |
| - */ |
188 |
| -abstract private class NormalizableFilepath extends string { |
189 |
| - bindingset[this] |
190 |
| - NormalizableFilepath() { any() } |
191 |
| - |
192 |
| - /** Gets the normalized filepath for this string; traversing `/../` paths. */ |
193 |
| - string getNormalizedPath() { |
194 |
| - exists(string norm | |
195 |
| - norm = this.getNormalizedUpTo(0).regexpReplaceAll("/+$", "") and |
196 |
| - (if this.matches("/%") then result = "/" + norm else result = norm) |
197 |
| - ) |
198 |
| - } |
199 |
| - |
200 |
| - private string getComponent(int i) { result = this.splitAt("/", i) } |
201 |
| - |
202 |
| - private int getNumComponents() { result = strictcount(int i | exists(this.getComponent(i))) } |
203 |
| - |
204 |
| - private string getNormalizedUpTo(int i) { |
205 |
| - i in [0 .. this.getNumComponents()] and |
206 |
| - ( |
207 |
| - i = this.getNumComponents() and |
208 |
| - result = "" |
209 |
| - or |
210 |
| - i < this.getNumComponents() and |
211 |
| - exists(string comp, string sofar | |
212 |
| - comp = this.getComponent(i) and sofar = this.getNormalizedUpTo(i + 1) |
213 |
| - | |
214 |
| - if comp = [".", ""] |
215 |
| - then result = sofar |
216 |
| - else |
217 |
| - if comp = ".." or not sofar.matches("../%") |
218 |
| - then result = comp + "/" + sofar |
219 |
| - else exists(string base | sofar = "../" + base | result = base) |
220 |
| - ) |
221 |
| - ) |
222 |
| - } |
223 |
| -} |
0 commit comments