MCPcopy Create free account
hub / github.com/apple/password-manager-resources / _parseCustomCharacterClass

Function _parseCustomCharacterClass

tools/PasswordRulesParser.js:313–366  ·  view source on GitHub ↗
(input, position)

Source from the content-addressed store, hash-verified

311}
312
313function _parseCustomCharacterClass(input, position)
314{
315 console.assert(position >= 0);
316 console.assert(position < input.length);
317 console.assert(input[position] === CHARACTER_CLASS_START_SENTINEL);
318
319 let length = input.length;
320 ++position;
321 if (position >= length) {
322 console.error("Found end-of-line instead of character class character");
323 return [null, position];
324 }
325
326 let initialPosition = position;
327 let result = [];
328 do {
329 let c = input[position];
330 if (!_isASCIIPrintableCharacter(c)) {
331 ++position;
332 continue;
333 }
334
335 if (c === "-" && (position - initialPosition) > 0) {
336 console.error("Ignoring '-'; a '-' may only appear as the first character in a character class");
337 ++position;
338 continue;
339 }
340
341 result.push(c);
342 ++position;
343 if (c === CHARACTER_CLASS_END_SENTINEL) {
344 break;
345 }
346 } while (position < length);
347
348 if (position < length && input[position] !== CHARACTER_CLASS_END_SENTINEL || position == length && input[position - 1] == CHARACTER_CLASS_END_SENTINEL) {
349 // Fix up result; we over consumed.
350 result.pop();
351 if (position < length) {
352 let nextCharacter = input[position];
353 if (!_isASCIIWhitespace(nextCharacter) && nextCharacter !== PROPERTY_VALUE_SEPARATOR && nextCharacter !== PROPERTY_SEPARATOR) {
354 console.error(`A ']' inside a character class must be the last character of the class; if a literal ']' is intended, write ']]' at the end. Found unexpected '${nextCharacter}' after closing ']'.`);
355 }
356 }
357 return [result, position];
358 }
359
360 if (position < length && input[position] == CHARACTER_CLASS_END_SENTINEL) {
361 return [result, position + 1];
362 }
363
364 console.error("Found end-of-line instead of end of character class");
365 return [null, position];
366}
367
368function _parsePasswordRequiredOrAllowedPropertyValue(input, position)
369{

Calls 2

_isASCIIWhitespaceFunction · 0.85

Tested by

no test coverage detected