Skip to content

Commit

Permalink
fix(autocomplete-valid): incomplete for invalid but safe values
Browse files Browse the repository at this point in the history
autocomplete="text" incompletes

Refs: #4492
  • Loading branch information
gaiety-deque committed Jun 11, 2024
1 parent 2481379 commit 1515f72
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/checks/forms/autocomplete-valid-evaluate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isValidAutocomplete } from '../../commons/text';

function autocompleteValidEvaluate(node, options, virtualNode) {
function autocompleteValidEvaluate(_node, options, virtualNode) {
const autocomplete = virtualNode.attr('autocomplete') || '';
return isValidAutocomplete(autocomplete, options);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/checks/forms/autocomplete-valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"impact": "serious",
"messages": {
"pass": "the autocomplete attribute is correctly formatted",
"fail": "the autocomplete attribute is incorrectly formatted"
"fail": "the autocomplete attribute is incorrectly formatted",
"incomplete": "the autocomplete attribute is incorrect but safe to use"
}
},
"options": {
Expand Down
8 changes: 7 additions & 1 deletion lib/commons/text/is-valid-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export const autocomplete = {
'email',
'impp'
],
locations: ['billing', 'shipping']
locations: ['billing', 'shipping'],
invalidButSafe: ['text']
};

function isValidAutocomplete(
Expand Down Expand Up @@ -117,6 +118,11 @@ function isValidAutocomplete(
}

const purposeTerm = autocompleteTerms[autocompleteTerms.length - 1];

if (autocomplete.invalidButSafe.includes(purposeTerm)) {
return undefined;
}

return (
standaloneTerms.includes(purposeTerm) ||
qualifiedTerms.includes(purposeTerm)
Expand Down
3 changes: 2 additions & 1 deletion locales/_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,8 @@
},
"autocomplete-valid": {
"pass": "the autocomplete attribute is correctly formatted",
"fail": "the autocomplete attribute is incorrectly formatted"
"fail": "the autocomplete attribute is incorrectly formatted",
"incomplete": "the autocomplete attribute is incorrect but safe to use"
},
"accesskeys": {
"pass": "Accesskey attribute value is unique",
Expand Down
5 changes: 5 additions & 0 deletions test/checks/forms/autocomplete-valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ describe('autocomplete-valid', function () {
assert.isFalse(evaluate.apply(checkContext, params));
});

it('returns undefined (incomplete) if autocomplete is not valid but safe', function () {
var params = checkSetup('<input autocomplete="text" id="target" />');
assert.isUndefined(evaluate.apply(checkContext, params));
});

it('uses options to change what is valid autocomplete', function () {
var options = { stateTerms: ['foo'] };
var params = checkSetup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,6 @@
<input autocomplete="section-foo email webauthn" id="pass92" />
<input autocomplete="section-foo work email webauthn" id="pass93" />
<input autocomplete="section-foo billing work email webauthn" id="pass94" />

<!-- Incomplete, invalid but safe values -->
<input autocomplete="text" id="incomplete1" />
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"description": "autocomplete-valid tests",
"rule": "autocomplete-valid",
"violations": [["#fail1"], ["#fail2"], ["#fail3"], ["#fail4"], ["#fail5"]],
"incomplete": [["#incomplete1"]],
"passes": [
["#pass1"],
["#pass2"],
Expand Down

0 comments on commit 1515f72

Please sign in to comment.