diff --git a/lib/core/base/audit.js b/lib/core/base/audit.js index 86df69b490..055f78f12c 100644 --- a/lib/core/base/audit.js +++ b/lib/core/base/audit.js @@ -297,7 +297,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] = {}; diff --git a/test/core/base/audit.js b/test/core/base/audit.js index f5d8df59ee..cc52a98130 100644 --- a/test/core/base/audit.js +++ b/test/core/base/audit.js @@ -149,6 +149,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 () {