* _parseHashParam * Converts hash parameters for severity overrides to regex matchers * @param {String} val - The value retrieved, e.g. `crossing_ways/bridge*,crossing_ways/tunnel*` * @return {Array} Array of Objects like { type: RegExp, subtype: RegExp }
(val = '')
| 173 | * @return {Array} Array of Objects like { type: RegExp, subtype: RegExp } |
| 174 | */ |
| 175 | _parseHashParam(val = '') { |
| 176 | let result = []; |
| 177 | const rules = val.split(',').map(s => s.trim()).filter(Boolean); |
| 178 | for (const rule of rules) { |
| 179 | const parts = rule.split('/', 2); // "type/subtype" |
| 180 | const type = parts[0]; |
| 181 | const subtype = parts[1] ?? '*'; |
| 182 | if (!type || !subtype) continue; |
| 183 | result.push({ type: makeRegExp(type), subtype: makeRegExp(subtype) }); |
| 184 | } |
| 185 | return result; |
| 186 | |
| 187 | function makeRegExp(str) { |
| 188 | const escaped = str |
| 189 | .replace(/[-\/\\^$+?.()|[\]{}]/g, '\\$&') // escape all reserved chars except for the '*' |
| 190 | .replace(/\*/g, '.*'); // treat a '*' like '.*' |
| 191 | return new RegExp(`^${escaped}$`); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | |
| 196 | /** |