Skip to content

Commit

Permalink
fix(core): Incomplete fallback was missing, and could cause infinite …
Browse files Browse the repository at this point in the history
…loop (#3302)
  • Loading branch information
WilcoFiers authored Nov 24, 2021
1 parent ef45377 commit f23d8c8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 19 deletions.
12 changes: 3 additions & 9 deletions build/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,10 @@ function buildRules(grunt, options, commons, callback) {
}

function getIncompleteMsg(summaries) {
var result = {};
summaries.forEach(function(summary) {
if (
summary.incompleteFallbackMessage &&
doTRegex.test(summary.incompleteFallbackMessage)
) {
result = doT.template(summary.incompleteFallbackMessage).toString();
}
var summary = summaries.find(function(summary) {
return typeof summary.incompleteFallbackMessage === 'string';
});
return result;
return summary ? summary.incompleteFallbackMessage : '';
}

function replaceFunctions(string) {
Expand Down
15 changes: 9 additions & 6 deletions lib/core/reporters/helpers/incomplete-fallback-msg.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
* This mechanism allows the string to be localized.
* @return {String}
*/
function incompleteFallbackMessage() {
return typeof axe._audit.data.incompleteFallbackMessage === 'function'
? axe._audit.data.incompleteFallbackMessage()
: axe._audit.data.incompleteFallbackMessage;
export default function incompleteFallbackMessage() {
let { incompleteFallbackMessage } = axe._audit.data;
if (typeof incompleteFallbackMessage === 'function') {
incompleteFallbackMessage = incompleteFallbackMessage();
}
if (typeof incompleteFallbackMessage !== 'string') {
return '';
}
return incompleteFallbackMessage;
}

export default incompleteFallbackMessage;
47 changes: 43 additions & 4 deletions test/core/reporters/helpers/incomplete-fallback-msg.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
describe('helpers.incompleteFallbackMessage', function() {
'use strict';
beforeEach(function() {

it('returns a non-empty string by default', function () {
var summary = helpers.incompleteFallbackMessage();
assert.typeOf(summary, 'string');
assert.notEqual(summary, '');
});

it('should return a string', function() {
axe._load({
messages: {},
rules: [],
data: {
incompleteFallbackMessage: 'Dogs are the best'
}
});
});

it('should return a string', function() {
var summary = helpers.incompleteFallbackMessage();
assert.equal(summary, 'Dogs are the best');
});
Expand All @@ -29,4 +33,39 @@ describe('helpers.incompleteFallbackMessage', function() {
var summary = helpers.incompleteFallbackMessage();
assert.equal(summary, 'Dogs are the best');
});

describe('when passed an invalid value', function () {
it('returns `` when set to an object', function () {
axe._load({
messages: {},
rules: [],
data: {
incompleteFallbackMessage: {}
}
});
assert.equal(helpers.incompleteFallbackMessage(), '');
});

it('returns `` when set to null', function () {
axe._load({
messages: {},
rules: [],
data: {
incompleteFallbackMessage: null
}
});
assert.equal(helpers.incompleteFallbackMessage(), '');
});

it('returns `` when set to undefined', function () {
axe._load({
messages: {},
rules: [],
data: {
incompleteFallbackMessage: undefined
}
});
assert.equal(helpers.incompleteFallbackMessage(), '');
});
});
});

0 comments on commit f23d8c8

Please sign in to comment.