隔离、恢复、验证与平台治理:练习答案
练习解答
python
from pathlib import PurePosixPath
def allowed(path):
p=PurePosixPath(path)
return not p.is_absolute() and '..' not in p.parts and bool(p.parts) and p.parts[0] in {'src','tests'}
assert [allowed(x) for x in ['src/a','tests/a','docs/a','tests/../secret']]==[True,True,False,False]
print('scope variant passed')这里验证逻辑路径清单,不能替代解析符号链接后的实际边界。