Skip to content

Commit 6692653

Browse files
committed
Path transformer: handle Windows-style paths
And don't add slash to start of path patterns on Windows.
1 parent 2a23559 commit 6692653

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

python/extractor/semmle/projectlayout.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
import re
1313
from functools import total_ordering
1414
import sys
15+
from pathlib import PureWindowsPath
16+
import os
1517

1618
def get_renamer(filename):
1719
layout = load(filename)
1820
def rename(path):
1921
renamed = layout.artificial_path(path)
2022
return path if renamed is None else renamed
23+
if os.name == "nt":
24+
return lambda path: rename(PureWindowsPath(path).as_posix())
2125
return rename
2226

2327
def load(filename):
@@ -257,7 +261,7 @@ def __init__(self, path, line, virtual=None):
257261
exclude = path
258262
self._line = line;
259263
self._original = u'-' + exclude;
260-
if not exclude.startswith(u"/"):
264+
if os.name != 'nt' and not exclude.startswith(u"/"):
261265
exclude = u'/' + exclude
262266
if exclude.find(u"//") != -1:
263267
raise _error(u"Illegal '//' in exclude path", line)
@@ -274,14 +278,14 @@ def __init__(self, path, line, virtual=None):
274278
include = path
275279
self._line = line;
276280
self._original = include;
277-
if not include.startswith(u"/"):
281+
if os.name != 'nt' and not include.startswith(u"/"):
278282
include = u'/' + include
279283
doubleslash = include.find(u"//")
280284
if doubleslash != include.find(u"//"):
281285
raise _error(u"More than one '//' in include path (project-layout)", line)
282286
if self._verify_stars.match(include):
283287
raise _error(u"Illegal use of '**' in include path (project-layout)", line)
284-
if not virtual.startswith(u"/"):
288+
if os.name != 'nt' and not virtual.startswith(u"/"):
285289
virtual = u"/" + virtual
286290
if virtual.endswith(u"/"):
287291
virtual = virtual[0 : -1]

0 commit comments

Comments
 (0)