-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(meta-refresh): Add WCAG's 20-hour exception (#3525)
* fix(meta-refresh): Add WCAG's 20-hour exception * put refreshDelay in check data * Address feedback * More tweaks
- Loading branch information
1 parent
9c6b828
commit 5beb6c3
Showing
14 changed files
with
382 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
function metaRefreshEvaluate(node, options, virtualNode) { | ||
var content = virtualNode.attr('content') || '', | ||
parsedParams = content.split(/[;,]/); | ||
const separatorRegex = /[;,\s]/; | ||
const validRedirectNumRegex = /^[0-9.]+$/; | ||
|
||
return content === '' || parsedParams[0] === '0'; | ||
} | ||
export default function metaRefreshEvaluate(node, options, virtualNode) { | ||
const { minDelay, maxDelay } = options || {}; | ||
const content = (virtualNode.attr('content') || '').trim(); | ||
const [redirectStr] = content.split(separatorRegex); | ||
if (!redirectStr.match(validRedirectNumRegex)) { | ||
return true; | ||
} | ||
|
||
export default metaRefreshEvaluate; | ||
const redirectDelay = parseFloat(redirectStr); | ||
this.data({ redirectDelay }); | ||
if (typeof minDelay === 'number' && redirectDelay <= options.minDelay) { | ||
return true; | ||
} | ||
if (typeof maxDelay === 'number' && redirectDelay > options.maxDelay) { | ||
return true; | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
describe('meta-refresh fail', function() { | ||
'use strict'; | ||
|
||
it('should be a violation', function(done) { | ||
axe.run({ runOnly: 'meta-refresh' }, function(err, results) { | ||
try { | ||
assert.isNull(err); | ||
assert.lengthOf(results.violations, 1, 'violations'); | ||
assert.lengthOf(results.passes, 0, 'passes'); | ||
assert.lengthOf(results.incomplete, 0, 'passes'); | ||
assert.lengthOf(results.inapplicable, 0, 'inapplicable'); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
test/integration/full/meta-refresh/meta-refresh-fail1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf8" /> | ||
<title>Meta-refresh fail 1</title> | ||
<meta http-equiv="refresh" content="10 https://deque.com/"> | ||
<link | ||
rel="stylesheet" | ||
type="text/css" | ||
href="/node_modules/mocha/mocha.css" | ||
/> | ||
<script src="/node_modules/mocha/mocha.js"></script> | ||
<script src="/node_modules/chai/chai.js"></script> | ||
<script src="/axe.js"></script> | ||
<script> | ||
mocha.setup({ | ||
timeout: 10000, | ||
ui: 'bdd' | ||
}); | ||
var assert = chai.assert; | ||
</script> | ||
</head> | ||
<body> | ||
<div id="mocha"></div> | ||
<script src="meta-refresh-fail.js"></script> | ||
<script src="/test/integration/adapter.js"></script> | ||
</body> | ||
</html> |
18 changes: 18 additions & 0 deletions
18
test/integration/full/meta-refresh/meta-refresh-inapplicable.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
describe('meta-refresh inapplicable', function() { | ||
'use strict'; | ||
|
||
it('should be inapplicable', function(done) { | ||
axe.run({ runOnly: 'meta-refresh' }, function(err, results) { | ||
try { | ||
assert.isNull(err); | ||
assert.lengthOf(results.violations, 0, 'violations'); | ||
assert.lengthOf(results.passes, 0, 'passes'); | ||
assert.lengthOf(results.incomplete, 0, 'passes'); | ||
assert.lengthOf(results.inapplicable, 1, 'inapplicable'); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
test/integration/full/meta-refresh/meta-refresh-inapplicable1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf8" /> | ||
<title>Meta-refresh inapplicable 1</title> | ||
<!-- no content attribute --> | ||
<meta http-equiv="refresh"> | ||
<link | ||
rel="stylesheet" | ||
type="text/css" | ||
href="/node_modules/mocha/mocha.css" | ||
/> | ||
<script src="/node_modules/mocha/mocha.js"></script> | ||
<script src="/node_modules/chai/chai.js"></script> | ||
<script src="/axe.js"></script> | ||
<script> | ||
mocha.setup({ | ||
timeout: 10000, | ||
ui: 'bdd' | ||
}); | ||
var assert = chai.assert; | ||
</script> | ||
</head> | ||
<body> | ||
<div id="mocha"></div> | ||
<script src="meta-refresh-inapplicable.js"></script> | ||
<script src="/test/integration/adapter.js"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.