Unify path filtering across POSIX and Windows (#1196)

* Unify path filtering across POSIX and Windows

Path filtering is performed on absolute paths, which causes regexps
to not work uniformly across OSes, due to the different path separator
(forward vs backward slashes). This converts paths to POSIX-style
before filtering, so that regexps can be written in a single style
and work across all systems.

Fixes: #1191

* Revert path behavior for "ignore comment" checks
pull/1300/head
Emilio López 2 years ago committed by GitHub
parent 89852f0c6f
commit 8bead9347c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      slither/core/slither_core.py

@ -4,6 +4,7 @@
import json
import logging
import os
import pathlib
import posixpath
import re
from typing import Optional, Dict, List, Set, Union
@ -218,8 +219,12 @@ class SlitherCore(Context):
for elem in r["elements"]
if "source_mapping" in elem
]
source_mapping_elements = map(
lambda x: posixpath.normpath(x) if x else x, source_mapping_elements
# Use POSIX-style paths so that filter_paths works across different
# OSes. Convert to a list so elements don't get consumed and are lost
# while evaluating the first pattern
source_mapping_elements = list(
map(lambda x: pathlib.Path(x).resolve().as_posix() if x else x, source_mapping_elements)
)
matching = False

Loading…
Cancel
Save