dreamhead / moco

Easy Setup Stub Server
MIT License
4.36k stars 1.08k forks source link

InvalidPathException Throws when set GlobalSettings include many files #294

Open sdliang1013 opened 3 years ago

sdliang1013 commented 3 years ago

现象:

  1. globalsettings设置include为*.json
    [{
    "context": "/mock/api",
    "file_root": "src/test/resources/moco",
    "include": "*.json"
    }]
  2. 启动报错:
    java.nio.file.InvalidPathException: Illegal char <*> at index 24: src\test\resources\moco\*.json
    at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
    at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
    at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
    at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
    at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
    at java.nio.file.Paths.get(Paths.java:84)
    at com.github.dreamhead.moco.util.Globs.getGlobPath(Globs.java:31)
    at com.github.dreamhead.moco.util.Globs.glob(Globs.java:20)
    at com.github.dreamhead.moco.parser.model.GlobalSetting.includes(GlobalSetting.java:22)

问题分析: GlobalSetting.includes -> Globs.glob -> Globs.getGlobPath -> Paths.get 方法在验证文件名时: *号为非法符号.

处理建议: 修改 Globs.glob方法, 不用Path做路径分析, 手动解析字符串实现searchPath的功能