Skip to content

Commit

Permalink
Merge branch 'hexojs:master' into fix_url_for
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaslanjaka authored Jan 19, 2024
2 parents b045658 + 7b28c4b commit 82d56b3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
8 changes: 7 additions & 1 deletion lib/permalink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ class Permalink {
}

stringify(data) {
return this.rule.replace(rParam, (match, name) => data[name]);
return this.rule.replace(rParam, (match, name) => {
const descriptor = Object.getOwnPropertyDescriptor(data, name);
if (descriptor && typeof descriptor.get === 'function') {
throw new Error('Invalid permalink setting!');
}
return data[name];
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-util",
"version": "3.1.0",
"version": "3.2.0",
"description": "Utilities for Hexo.",
"main": "dist/index",
"types": "./dist/index.d.ts",
Expand Down
16 changes: 16 additions & 0 deletions test/permalink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,20 @@ describe('Permalink', () => {
title: 'test'
}).should.eql('2014/01/31/test');
});

it('stringify() - avoid infinite loops', () => {
const post = {
get path() {
return this.permalink;
},

get permalink() {
const permalink = new Permalink('/:permalink');
return permalink.stringify(post);
}
};

(() => post.path).should.throw('Invalid permalink setting!');
(() => post.permalink).should.throw('Invalid permalink setting!');
});
});
14 changes: 4 additions & 10 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@
"outDir": "dist",
"declaration": true,
"esModuleInterop": true,
"types": [
"node"
],
"types": ["node"],
"lib": ["ES2020", "ES2019"]
},
"include": [
"lib/index.ts"
],
"exclude": [
"node_modules"
]
}
"include": ["lib/**.ts"],
"exclude": ["node_modules"]
}

0 comments on commit 82d56b3

Please sign in to comment.