Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/lint-scripts/password-rules-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
//
// Validates every "password-rules" string in quirks/password-rules.json by
// loading tools/PasswordRulesParser.js and calling parsePasswordRules() on it.
// Any parse error (e.g. ",required" instead of "; required", as in #907) causes
// CI to fail with a clear message identifying the offending domain.
// Any parse error (e.g. ",required" instead of "; required" as in #907, or
// '-'/']' in the wrong position inside a character class) causes CI to fail
// with a clear message identifying the offending domain.

"use strict";

Expand Down
11 changes: 8 additions & 3 deletions tools/PasswordRulesParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,7 @@ function _parseCustomCharacterClass(input, position)
}

if (c === "-" && (position - initialPosition) > 0) {
// FIXME: Should this be an error?
console.warn("Ignoring '-'; a '-' may only appear as the first character in a character class");
console.error("Ignoring '-'; a '-' may only appear as the first character in a character class");
++position;
continue;
}
Expand All @@ -349,6 +348,12 @@ function _parseCustomCharacterClass(input, position)
if (position < length && input[position] !== CHARACTER_CLASS_END_SENTINEL || position == length && input[position - 1] == CHARACTER_CLASS_END_SENTINEL) {
// Fix up result; we over consumed.
result.pop();
if (position < length) {
let nextCharacter = input[position];
if (!_isASCIIWhitespace(nextCharacter) && nextCharacter !== PROPERTY_VALUE_SEPARATOR && nextCharacter !== PROPERTY_SEPARATOR) {
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 ']'.`);
}
}
return [result, position];
}

Expand Down Expand Up @@ -513,7 +518,7 @@ function _parsePasswordRulesInternal(input)
var position = _indexOfNonWhitespaceCharacter(input);
while (position < length) {
if (!_isIdentifierCharacter(input[position])) {
console.warn("Failed to find start of property: " + input.substr(position));
console.error("Failed to find start of property: " + input.substr(position));
return parsedProperties;
}

Expand Down