Skip to content

Commit 61c7956

Browse files
committed
Allow access to prototype properties
1 parent 8ad2af9 commit 61c7956

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/sprintf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
if (ph.keys) { // keyword argument
4242
arg = argv[cursor]
4343
for (k = 0; k < ph.keys.length; k++) {
44-
if (!arg.hasOwnProperty(ph.keys[k])) {
44+
if (arg[ph.keys[k]] === undefined) {
4545
throw new Error(sprintf('[sprintf] property "%s" does not exist', ph.keys[k]))
4646
}
4747
arg = arg[ph.keys[k]]

test/test_validation.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,14 @@ describe('sprintfjs', function() {
5858
})
5959
})
6060
})
61+
62+
describe('sprintfjs-prototype', function() {
63+
64+
function Klass() {}
65+
Klass.prototype = {
66+
get x() { return 2 }
67+
}
68+
it('Prototype properties should not cause an error', function() {
69+
should_not_throw('%(x)s', new Klass())
70+
})
71+
})

0 commit comments

Comments
 (0)