Skip to content

Commit

Permalink
fix: Match prerelease versions for helpUrl (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers authored and marcysutton committed Sep 25, 2017
1 parent c72badb commit 5300577
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/core/base/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ function getHelpUrl ({brand, application}, ruleId, version) {
}

Audit.prototype._constructHelpUrls = function (previous = null) {
var version = axe.version.substring(0, axe.version.lastIndexOf('.'));
var version = (axe.version.match(/^[1-9][0-9]*\.[1-9][0-9]*/) || ['x.y'])[0];
this.rules.forEach(rule => {
if (!this.data.rules[rule.id]) {
this.data.rules[rule.id] = {};
Expand Down
32 changes: 32 additions & 0 deletions test/core/base/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,38 @@ describe('Audit', function () {
'https://dequeuniversity.com/rules/thing/x.y/target2?application=axeAPI'
);
});
it('understands prerelease type version numbers', function () {
var tempVersion = axe.version;
var audit = new Audit();
audit.addRule({
id: 'target',
matches: 'function () {return "hello";}',
selector: 'bob'
});

axe.version = '3.2.1-alpha.0';
audit._constructHelpUrls();

axe.version = tempVersion;
assert.equal(audit.data.rules.target.helpUrl,
'https://dequeuniversity.com/rules/axe/3.2/target?application=axeAPI');
});
it('sets x.y as version for invalid versions', function () {
var tempVersion = axe.version;
var audit = new Audit();
audit.addRule({
id: 'target',
matches: 'function () {return "hello";}',
selector: 'bob'
});

axe.version = 'in-3.0-valid';
audit._constructHelpUrls();

axe.version = tempVersion;
assert.equal(audit.data.rules.target.helpUrl,
'https://dequeuniversity.com/rules/axe/x.y/target?application=axeAPI');
});
});

describe('Audit#setBranding', function () {
Expand Down

0 comments on commit 5300577

Please sign in to comment.