| 112 | static const string* dotdot = new string(".."); |
| 113 | |
| 114 | foreach (const string& component, components) { |
| 115 | CHECK(!component.empty()); // `tokenize` does not return empty tokens. |
| 116 | |
| 117 | if (component == *dot) { |
| 118 | return Error("Role '" + role + "' cannot include '.' as a component"); |
| 119 | } |
| 120 | |
| 121 | if (component == *dotdot) { |
| 122 | return Error("Role '" + role + "' cannot include '..' as a component"); |
| 123 | } |
| 124 | |
| 125 | if (component == *star) { |
| 126 | return Error("Role '" + role + "' cannot include '*' as a component"); |
| 127 | } |
| 128 | |
| 129 | if (strings::startsWith(component, '-')) { |
| 130 | return Error("Role component '" + component + "' is invalid " |
| 131 | "because it starts with a dash"); |
| 132 | } |
| 133 | |
| 134 | if (component.find_first_of(*INVALID_CHARACTERS) != string::npos) { |
| 135 | return Error("Role component '" + component + "' is invalid " |
| 136 | "because it contains backspace or whitespace"); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | return None(); |
| 141 | } |