MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / validateBasePath

Function validateBasePath

source/base/StarAssets.cpp:27–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25namespace Star {
26
27static 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
62static void validatePath(AssetPath const& components, bool canContainSubPath, bool canContainDirectives) {
63 validateBasePath(components.basePath.utf8());

Callers 1

validatePathFunction · 0.85

Calls 2

strfFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected