| 25 | namespace Star { |
| 26 | |
| 27 | static void validateBasePath(std::string_view const& basePath) { |
| 28 | if (basePath.empty() || basePath[0] != '/') |
| 29 | throw AssetException(strf("Path '{}' must be absolute", basePath)); |
| 30 | |
| 31 | bool first = true; |
| 32 | bool slashed = true; |
| 33 | bool dotted = false; |
| 34 | for (auto c : basePath) { |
| 35 | if (c == '/') { |
| 36 | if (!first) { |
| 37 | if (slashed) |
| 38 | throw AssetException(strf("Path '{}' contains consecutive //, not allowed", basePath)); |
| 39 | else if (dotted) |
| 40 | throw AssetException(strf("Path '{}' '.' and '..' not allowed", basePath)); |
| 41 | } |
| 42 | slashed = true; |
| 43 | dotted = false; |
| 44 | } else if (c == ':') { |
| 45 | if (slashed) |
| 46 | throw AssetException(strf("Path '{}' has ':' after directory", basePath)); |
| 47 | break; |
| 48 | } else if (c == '?') { |
| 49 | if (slashed) |
| 50 | throw AssetException(strf("Path '{}' has '?' after directory", basePath)); |
| 51 | break; |
| 52 | } else { |
| 53 | slashed = false; |
| 54 | dotted = c == '.'; |
| 55 | } |
| 56 | first = false; |
| 57 | } |
| 58 | if (slashed) |
| 59 | throw AssetException(strf("Path '{}' cannot be a file", basePath)); |
| 60 | } |
| 61 | |
| 62 | static void validatePath(AssetPath const& components, bool canContainSubPath, bool canContainDirectives) { |
| 63 | validateBasePath(components.basePath.utf8()); |
no test coverage detected