[go: up one dir, main page]

Skip to content

Commit

Permalink
Use getSafeProperty in help
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Jun 30, 2017
1 parent 142e200 commit 485cb88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/expression/function/help.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var getSafeProperty = require('../../utils/customs').getSafeProperty;

function factory (type, config, load, typed, math) {
var docs = load(require('../docs'));

Expand Down Expand Up @@ -50,7 +52,7 @@ function factory (type, config, load, typed, math) {
*/
}

var doc = docs[name];
var doc = getSafeProperty(docs, name);
if (!doc) {
throw new Error('No documentation found on "' + name + '"');
}
Expand Down
4 changes: 4 additions & 0 deletions test/expression/function/help.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ describe('help', function() {
assert.equal(help.doc.name, 'pi');
});

it('should not allow accessing unsafe properties ', function() {
assert.throws(function () {math.help('constructor')}, /No access/);
});

it('should throw an error when no help is found', function() {
// assert.throws(function () {math.help(undefined)}, /No documentation found/);
assert.throws(function () {math.help(new Date())}, /No documentation found/);
Expand Down

0 comments on commit 485cb88

Please sign in to comment.