diff --git a/shared/yaml/codeql/yaml/Yaml.qll b/shared/yaml/codeql/yaml/Yaml.qll index 028654de226c..1467fd09d137 100644 --- a/shared/yaml/codeql/yaml/Yaml.qll +++ b/shared/yaml/codeql/yaml/Yaml.qll @@ -424,14 +424,24 @@ module Make { * Gets the absolute path of the file included by this directive. */ private string getTargetPath() { - exists(string path | path = this.getValue() | - if path.matches("/%") - then result = path - else - result = - this.getDocument().getLocation().getFile().getParentContainer().getAbsolutePath() + "/" + - path - ) + result = this.getAbsolutePath() + or + result = + this.getDocument().getLocation().getFile().getParentContainer().getAbsolutePath() + "/" + + this.getRelativePath() + } + + /** Join-order helper for `getTargetPath`. Gets the path but only if it is an absolute path. */ + private string getAbsolutePath() { + result = this.getValue() and + result.matches("/%") + } + + /** Join-order helper for `getTargetPath`. Gets the path, but only if it is a relative path. */ + pragma[noinline] + private string getRelativePath() { + result = this.getValue() and + not result.matches("/%") } }