Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Commit 7e8d83f

Browse files
committed
Fix: Removed prototype pollution.
Converted the `toProperCase` prototype pollution into a non-polluting function.
1 parent 7abcb04 commit 7e8d83f

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

commands/help.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ a command, it is not shown to them. If a command name is given with the
66
help command, its extended help is shown.
77
*/
88
const { codeBlock } = require("@discordjs/builders");
9+
const { toProperCase } = require("../modules/functions.js");
910

1011
exports.run = (client, message, args, level) => {
1112
// Grab the container from the client to reduce line length.
@@ -34,7 +35,7 @@ exports.run = (client, message, args, level) => {
3435
p.help.name > c.help.name && p.help.category === c.help.category ? 1 : -1 );
3536

3637
sorted.forEach( c => {
37-
const cat = c.help.category.toProperCase();
38+
const cat = toProperCase(c.help.category);
3839
if (currentCategory !== cat) {
3940
output += `\u200b\n== ${cat} ==\n`;
4041
currentCategory = cat;

modules/functions.js

+6-13
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,11 @@ async function awaitReply(msg, question, limit = 60000) {
7575

7676
/* MISCELLANEOUS NON-CRITICAL FUNCTIONS */
7777

78-
// EXTENDING NATIVE TYPES IS BAD PRACTICE. Why? Because if JavaScript adds this
79-
// later, this conflicts with native code. Also, if some other lib you use does
80-
// this, a conflict also occurs. KNOWING THIS however, the following 2 methods
81-
// are, we feel, very useful in code.
82-
83-
// <String>.toProperCase() returns a proper-cased string such as:
84-
// "Mary had a little lamb".toProperCase() returns "Mary Had A Little Lamb"
85-
Object.defineProperty(String.prototype, "toProperCase", {
86-
value: function() {
87-
return this.replace(/([^\W_]+[^\s-]*) */g, (txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase());
88-
}
89-
});
78+
// toProperCase(String) returns a proper-cased string such as:
79+
// toProperCase("Mary had a little lamb") returns "Mary Had A Little Lamb"
80+
function toProperCase(string) {
81+
return string.replace(/([^\W_]+[^\s-]*) */g, (txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase());
82+
}
9083

9184
// These 2 process methods will catch exceptions and give *more details* about the error and stack trace.
9285
process.on("uncaughtException", (err) => {
@@ -103,4 +96,4 @@ process.on("unhandledRejection", err => {
10396
console.error(err);
10497
});
10598

106-
module.exports = { getSettings, permlevel, awaitReply };
99+
module.exports = { getSettings, permlevel, awaitReply, toProperCase };

0 commit comments

Comments
 (0)