Closed TheBunnyMan123 closed 4 months ago
There's already string.find(str, regex)
in regular Lua. What's the point of this PR?
There's already
string.find(str, regex)
in regular Lua. What's the point of this PR?
Regular Lua does not use regex for its matches. It uses Lua Patterns.
inb4 /a+(b|(c|d+)+)+e/
. Try matching that against e.g. "adddddddddddddddddddddddddddddddddddddddddddf" and your game will likely freeze for a while or crash. Do we have any way to prevent this?
Edit: Nearly guaranteed to crash your game:
repeat until client.regexMatch("a" .. ("d"):rep(1000) .. "f", "a+(b|(c|+)+)+e")
Also, while you're at it, is there a way to expose the regex's group ((
...)
) matches when it successfully matches?
What do you mean by exist the group if it matches?
Also, I can place a maximum time of, say, 10 seconds before forcing it to stop.
What do you mean by exist the group if it matches?
JS's RegExp.exec
returns an array* of the capture group contents so you can refer to subparts of the matched pattern. I don't know if Java has something similar, but if it does it'd probably be useful to expose.
Also, I can place a maximum time of, say, 10 seconds before forcing it to stop.
Yeah, but in a loop that's iirc 3 instructions to freeze the game for 10 seconds each. Combined with the relatively high number of instructions in TICK and RENDER, this lets you lower other people's FPS to near-mine incredibly easily.
Yeah, I'm going to see if I can think of a way to stop that. One thing I could do is cache the results, so if you input a duplicate string and expression it will just return the same value, but that wouldn't prevent randomness. I could also put a cap on the max string sizes.
I could also track if it is run more than, say, 5 times a second and error out the avatar running it
Oh but pcall. I could also disable new calculations for 1 minute and give a toast saying what is happening
JS's
RegExp.exec
returns an array* of the capture group contents so you can refer to subparts of the matched pattern. I don't know if Java has something similar, but if it does it'd probably be useful to expose.
There are Matcher#group(int)
, Matcher#groupCount()
and a lot more methods that help to get match subparts in Java, so it is completely possible to expose these to Lua, what I agree would be useful.
One potential way to limit the time taken is to implement regex in Lua, then instructions will be counted while processing the regex. You can make it come with all avatars, kind of like how Figura already defines new things in the math library.
One potential way to limit the time taken is to implement regex in Lua, then instructions will be counted while processing the regex. You can make it come with all avatars, kind of like how Figura already defines new things in the math library.
Potentially it could instead be implemented in Java for performance, using Avatar::punish
to make matching still cost instructions? I don't know if mixins work in system libraries, but if they do I will certainly be happy to abuse them for this.
That is a great idea, I just gotta figure out a good scale Factor
I'm not going to work on this further. Too much work for something that helps very little. Closing.
Actually I'm gonna make it host only I don't want to manually parse links. That also fixes the issue of crashing other players
It is host only now. I can still add an avatar:punish if needed
also I checked and can't find a way to give what matched. best we can do is have the user compare regexFind and regexReplace unless yall know something I dont
this doesn't fit with figura. closing
This adds a
client.regexMatch
function to figura.Example for capturing a link: