@@ -133,7 +133,7 @@ def from_dep_kind(cls, kind: str):
133
133
depended_target = next (filter (_is_lib_or_proc_macro , depended_package ['targets' ]), None )
134
134
if depended_target :
135
135
related_source_files = _related_source_files (basedir , _cargo_metadata_by_manifest_path (pathlib .Path (depended_package ["manifest_path" ])))
136
- ret |= _source_files_in_same_targets (pathlib .Path (depended_target ['src_path' ]), related_source_files )
136
+ ret |= _source_files_in_same_targets (pathlib .Path (depended_target ['src_path' ]). resolve ( strict = True ) , related_source_files )
137
137
return sorted (ret )
138
138
139
139
@@ -186,15 +186,15 @@ def _related_source_files(basedir: pathlib.Path, metadata: Dict[str, Any]) -> Di
186
186
s = s .rstrip ('\\ ' )
187
187
s += ' '
188
188
s += next (it )
189
- path = pathlib .Path (metadata ['workspace_root' ], s )
189
+ path = pathlib .Path (metadata ['workspace_root' ], s ). resolve ( strict = True )
190
190
# Ignores paths that don't start with the `basedir`. (e.g. `/dev/null`, `/usr/local/share/foo/bar`)
191
191
try :
192
192
# `PurePath.is_relative_to` is since Python 3.9.
193
193
_ = path .relative_to (basedir )
194
194
paths .append (path )
195
195
except ValueError :
196
196
pass
197
- if paths [:1 ] == [pathlib .Path (target ['src_path' ])]:
197
+ if paths [:1 ] == [pathlib .Path (target ['src_path' ]). resolve ( strict = True ) ]:
198
198
ret [paths [0 ]] = frozenset (paths [1 :])
199
199
break
200
200
else :
@@ -289,7 +289,7 @@ def is_verification_file(self, path: pathlib.Path, *, basedir: pathlib.Path) ->
289
289
if not package_and_target :
290
290
return False
291
291
_ , target = package_and_target
292
- return _is_bin_or_example_bin (target ) and 'PROBLEM' in special_comments .list_special_comments (pathlib . Path ( target [ 'src_path' ]) )
292
+ return _is_bin_or_example_bin (target ) and 'PROBLEM' in special_comments .list_special_comments (path )
293
293
294
294
def list_environments (self , path : pathlib .Path , * , basedir : pathlib .Path ) -> Sequence [RustLanguageEnvironment ]:
295
295
return [RustLanguageEnvironment ()]
@@ -298,10 +298,10 @@ def list_environments(self, path: pathlib.Path, *, basedir: pathlib.Path) -> Seq
298
298
def _cargo_metadata (cwd : pathlib .Path ) -> Dict [str , Any ]:
299
299
"""Runs `cargo metadata` for a Cargo.toml file in `cwd` or its parent directories.
300
300
301
- :raises ValueError: if `cwd` is not absolute
301
+ :raises ValueError: if `cwd` is not absolute or contains `..`
302
302
"""
303
- if not cwd .is_absolute ():
304
- raise ValueError (f'the `cwd` parameter must be absolute: { cwd } ' )
303
+ if not cwd .is_absolute () or '..' in cwd . parts :
304
+ raise ValueError (f'the `cwd` parameter must be absolute and must not contain `..` : { cwd } ' )
305
305
306
306
def find_root_manifest_for_wd () -> pathlib .Path :
307
307
# https://docs.rs/cargo/0.48.0/cargo/util/important_paths/fn.find_root_manifest_for_wd.html
@@ -341,7 +341,8 @@ def _find_target(
341
341
) -> Optional [Tuple [Dict [str , Any ], Dict [str , Any ]]]:
342
342
for package in metadata ['packages' ]:
343
343
for target in package ['targets' ]:
344
- if pathlib .Path (target ['src_path' ]) == src_path :
344
+ # A `src_path` may contain `..`
345
+ if pathlib .Path (target ['src_path' ]).resolve (strict = True ) == src_path :
345
346
return package , target
346
347
return None
347
348
0 commit comments