Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cvar pattern replacement #561

Closed
wants to merge 2 commits into from
Closed

Fix cvar pattern replacement #561

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Aug 17, 2023

This fixes an issue where executing commands similar to /say %$% with Client Commands installed would cause the client to crash.

@Earthcomputer
Copy link
Owner

Can you give a crash log/link an issue? I don't understand why the dollar sign would be special

@ghost
Copy link
Author

ghost commented Aug 17, 2023

Can you give a crash log/link an issue? I don't understand why the dollar sign would be special

Sure, here's the exception (with /say %$%):

net.minecraft.class_148: keyPressed event handler
	at net.minecraft.class_437.method_25412(class_437.java:414) ~[client-intermediary.jar:?]
	at net.minecraft.class_309.method_1466(class_309.java:391) ~[client-intermediary.jar:?]
	at net.minecraft.class_309.method_22678(class_309.java:477) ~[client-intermediary.jar:?]
	at net.minecraft.class_1255.execute(class_1255.java:102) ~[client-intermediary.jar:?]
	at net.minecraft.class_309.redirect$ccb000$viafabricplus$redirectSync(class_309.java:2112) ~[client-intermediary.jar:?]
	at net.minecraft.class_309.method_22676(class_309.java:477) ~[client-intermediary.jar:?]
	at org.lwjgl.glfw.GLFWKeyCallbackI.callback(GLFWKeyCallbackI.java:44) ~[lwjgl-glfw-3.3.1.jar:?]
	at org.lwjgl.system.JNI.invokeV(Native Method) ~[lwjgl-3.3.1.jar:?]
	at org.lwjgl.glfw.GLFW.glfwPollEvents(GLFW.java:3403) ~[lwjgl-glfw-3.3.1.jar:?]
	at com.mojang.blaze3d.systems.RenderSystem.pollEvents(RenderSystem.java:201) ~[client-intermediary.jar:?]
	at com.mojang.blaze3d.systems.RenderSystem.flipFrame(RenderSystem.java:219) ~[client-intermediary.jar:?]
	at net.minecraft.class_1041.method_15998(class_1041.java:288) ~[client-intermediary.jar:?]
	at net.minecraft.class_310.method_1523(class_310.java:1241) ~[client-intermediary.jar:?]
	at net.minecraft.class_310.method_1514(class_310.java:802) ~[client-intermediary.jar:?]
	at net.minecraft.client.main.Main.main(Main.java:250) ~[minecraft-1.20.1-client.jar:?]
	at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:468) ~[fabric-loader-0.14.22.jar:?]
	at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74) ~[fabric-loader-0.14.22.jar:?]
	at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23) ~[fabric-loader-0.14.22.jar:?]
	at org.prismlauncher.launcher.impl.StandardLauncher.launch(StandardLauncher.java:88) ~[NewLaunch.jar:?]
	at org.prismlauncher.EntryPoint.listen(EntryPoint.java:126) ~[NewLaunch.jar:?]
	at org.prismlauncher.EntryPoint.main(EntryPoint.java:71) ~[NewLaunch.jar:?]
Caused by: java.lang.IllegalArgumentException: Illegal group reference
	at java.util.regex.Matcher.appendExpandedReplacement(Matcher.java:1067) ~[?:?]
	at java.util.regex.Matcher.appendReplacement(Matcher.java:997) ~[?:?]
	at net.earthcomputer.clientcommands.command.VarCommand.replaceVariables(VarCommand.java:150) ~[clientcommands-2.8.3.jar:?]
	at net.minecraft.class_408.localvar$zbd000$clientcommands$onSendMessage(class_408.java:516) ~[client-intermediary.jar:?]
	at net.minecraft.class_408.method_44056(class_408.java:247) ~[client-intermediary.jar:?]
	at net.minecraft.class_408.method_25404(class_408.java:102) ~[client-intermediary.jar:?]
	at net.minecraft.class_309.method_1454(class_309.java:395) ~[client-intermediary.jar:?]
	at net.minecraft.class_437.method_25412(class_437.java:409) ~[client-intermediary.jar:?]
	... 20 more

@CzechHek
Copy link

CzechHek commented Aug 17, 2023

Can you give a crash log/link an issue? I don't understand why the dollar sign would be special

From what I see in the crash log, it is trying to replace $1 for first group match (and similarly) but it crashes when there isn't any number after the $ symbol (or it crashes because group referencing itself makes no sense?). Why is it even doing this tho?

I used this when replacing string parts using regular expressions.

@Earthcomputer
Copy link
Owner

See the Matcher.appendReplacement docs. Instead of doing this, you could replace all \ with \\ and then all $ with \$ in the replacement string.

@ghost ghost closed this by deleting the head repository Sep 11, 2023
@Earthcomputer Earthcomputer changed the title Do not match dollar signs in variable names Fix cvar pattern replacement Sep 11, 2023
Earthcomputer added a commit that referenced this pull request Sep 11, 2023
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants