Skip to content

Commit 3375a1c

Browse files
committed
new security function to validate maxItem
1 parent 6d00273 commit 3375a1c

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

lib/modules/global-parser/services/utils.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,37 @@ function gameUrlListSwitcher(cmdResponse) {
5454
}
5555
}
5656

57-
export { mongoImport, requestOpts, gameConfParserSwitcher, gameUrlListSwitcher };
57+
/**
58+
* Because "Class" is not a generic category, we need a dedicated method to init it & parse it
59+
* @param {Object} init contain all init variable
60+
* @returns {Array} Return an array which contain links of all class
61+
*/
62+
function parseEachPageLinksClass(init) {
63+
const links = [];
64+
init.$('.ak-content-sections').find('.ak-section').each(function (i, div) {
65+
if (!init.all) if (links.length >= init.maxItem) return false;
66+
const link = init.globalUrl + init.$(this).find('a').attr('href');
67+
links.push(link);
68+
});
69+
70+
return links;
71+
}
72+
73+
/**
74+
* Security to take care of not overpass real maxItem value
75+
* @param {Object} init contain all init variable
76+
* @returns {Number} Return the real maxItem in case of overpassing the real value
77+
*/
78+
function maxItemControl(init) {
79+
if (init.itemCategory == 'classe') {
80+
const realMaxItem = Number(init.$('.ak-content-sections').find('.ak-section').length);
81+
if (init.maxItem >= realMaxItem || init.all === true) init.maxItem = realMaxItem; // security line to avoid overpasing the real amont of items & to take care about 'all' value if true
82+
}
83+
else {
84+
const realMaxItem = Number(init.$('div.ak-list-info > strong').text()) === 0 ? init.$('tbody > tr').length : Number(init.$('div.ak-list-info > strong').text());
85+
if (init.maxItem >= realMaxItem || init.all === true) init.maxItem = realMaxItem; // security line to avoid overpasing the real amont of items & to take care about 'all' value if true
86+
}
87+
return init.maxItem;
88+
}
89+
90+
export { mongoImport, requestOpts, gameConfParserSwitcher, gameUrlListSwitcher, parseEachPageLinksClass, maxItemControl };

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dofapi/crawlit",
3-
"version": "1.5.12",
3+
"version": "1.6.12",
44
"homepage": "https://github.com/dofapi/crawlit-dofus-encyclopedia-parser",
55
"description": "Crawl structured dofus encyclopedia data to populate the Dofapi app & API",
66
"author": {

0 commit comments

Comments
 (0)