Optimize regex expressions
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ee4c5155fa
commit
b55a27fdfb
@ -67,7 +67,7 @@ public class MessageCommandListener extends ListenerAdapter
|
|||||||
String eventMessage = event.getMessage().getContentRaw();
|
String eventMessage = event.getMessage().getContentRaw();
|
||||||
|
|
||||||
// check if the sent message matches the bot activation regex (prefix, name, ...)
|
// check if the sent message matches the bot activation regex (prefix, name, ...)
|
||||||
if(!eventMessage.toLowerCase().matches(commandRegex + "((.|\\n)*)"))
|
if(!eventMessage.toLowerCase().matches("(?s)" + commandRegex + ".*"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// generate args from the string
|
// generate args from the string
|
||||||
|
@ -106,8 +106,11 @@ public class FormatUtil
|
|||||||
eg: 3d, 33hours, 32048dojg, 3d2h5m22s.
|
eg: 3d, 33hours, 32048dojg, 3d2h5m22s.
|
||||||
it does not match if the [digits and characters] blocks are missing.
|
it does not match if the [digits and characters] blocks are missing.
|
||||||
eg: 33, asd, 3g5hj, 4 asd.
|
eg: 33, asd, 3g5hj, 4 asd.
|
||||||
|
|
||||||
|
{1,10} is used to limit the size of the input to parse, to avoid stack overflows.
|
||||||
|
no one should be typing more than 10 arguments, or more than 10 digits for a single argument anyway.
|
||||||
*/
|
*/
|
||||||
if(!duration.matches("(\\d+[a-zA-Z]+)+"))
|
if(!duration.matches("(\\d{1,10}[a-zA-Z]{1,10}){1,10}"))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
String[] durationTimes = duration.split("[a-zA-Z]+");
|
String[] durationTimes = duration.split("[a-zA-Z]+");
|
||||||
|
Loading…
Reference in New Issue
Block a user