Browse Source

More safe properties check

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
761947f2fb
  1. 3
      demo/assets/index.css
  2. 2
      demo/assets/index.js
  3. 3
      demo/assets/index.styl
  4. 9
      lib/common/utils.js
  5. 3
      lib/renderer.js
  6. 3
      lib/rules_inline/entity.js

3
demo/assets/index.css

@ -97,6 +97,9 @@ body {
-webkit-column-count: 2;
column-count: 2;
}
.footnotes-list {
padding-left: 2em;
}
.gh-ribbon {
display: block;
position: absolute;

2
demo/assets/index.js

@ -118,7 +118,7 @@
// copy config to defaults, but only if key exists
// and value has the same type
_.forOwn(opts, function (val, key) {
if (!defaults.hasOwnProperty(key)) { return; }
if (!_.has(defaults, key)) { return; }
// Legacy, for old links
if (key === '_src') {

3
demo/assets/index.styl

@ -89,6 +89,9 @@ body
-webkit-column-count 2
column-count 2
.footnotes-list
padding-left 2em
.gh-ribbon
display block
position absolute

9
lib/common/utils.js

@ -7,6 +7,12 @@ function _class(obj) { return Object.prototype.toString.call(obj); }
function isString(obj) { return _class(obj) === '[object String]'; }
var _hasOwnProperty = Object.prototype.hasOwnProperty;
function has(object, key) {
return object ? _hasOwnProperty.call(object, key) : false;
}
// Merge objects
//
function assign(obj /*from1, from2, from3, ...*/) {
@ -74,7 +80,7 @@ var entities = require('./entities');
function replaceEntityPattern(match, name) {
var code = 0;
if (entities.hasOwnProperty(name)) {
if (has(entities, name)) {
return entities[name];
} else if (name.charCodeAt(0) === 0x23/* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) {
code = name[1].toLowerCase() === 'x' ?
@ -120,6 +126,7 @@ function escapeHtml(str) {
exports.assign = assign;
exports.isString = isString;
exports.has = has;
exports.unescapeMd = unescapeMd;
exports.isValidEntityCode = isValidEntityCode;
exports.fromCodePoint = fromCodePoint;

3
lib/renderer.js

@ -2,6 +2,7 @@
var assign = require('./common/utils').assign;
var has = require('./common/utils').has;
var unescapeMd = require('./common/utils').unescapeMd;
var replaceEntities = require('./common/utils').replaceEntities;
var escapeHtml = require('./common/utils').escapeHtml;
@ -73,7 +74,7 @@ rules.fence = function (tokens, idx, options, env, self) {
fenceName = token.params.split(/\s+/g)[0];
if (self.rules.fence_custom.hasOwnProperty(fenceName)) {
if (has(self.rules.fence_custom, fenceName)) {
return self.rules.fence_custom[fenceName](tokens, idx, options, env, self);
}

3
lib/rules_inline/entity.js

@ -3,6 +3,7 @@
'use strict';
var entities = require('../common/entities');
var has = require('../common/utils').has;
var isValidEntityCode = require('../common/utils').isValidEntityCode;
var fromCodePoint = require('../common/utils').fromCodePoint;
@ -32,7 +33,7 @@ module.exports = function entity(state, silent) {
} else {
match = state.src.slice(pos).match(NAMED_RE);
if (match) {
if (entities.hasOwnProperty(match[1])) {
if (has(entities, match[1])) {
if (!silent) { state.pending += entities[match[1]]; }
state.pos += match[0].length;
return true;

Loading…
Cancel
Save