Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -542,4 +542,19 @@ public static boolean containsUuid(String str) {
return UUID_PATTERN.matcher(str).find();
}

public static String escape(String value) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should have documentation describing its behavior.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not going to make any more changes to this, it’s a tiny merge to fix an annoyance I had- didn’t really intend on coming back in three weeks😭. I can move this it an issue instead if that’s better. Maintainer edits are also on.

if (value.isEmpty()) {
return "\"\"";
}
Comment on lines +546 to +548
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to handle an empty string like that?


boolean quote = value.indexOf(' ') >= 0 || value.indexOf('\t') >= 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the idea behind including \t here?

if (!quote) {
return value;
}

String escaped = value.replace("\\", "\\\\").replace("\"", "\\\"");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the intention behind this? It doesn't seem like Piston can deal with \" escaping, so this won't work if a file name contains a ".


return "\"" + escaped + "\"";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder;
import com.fastasyncworldedit.core.math.transform.MutatingOperationTransformHolder;
import com.fastasyncworldedit.core.util.MainUtil;
import com.fastasyncworldedit.core.util.StringMan;
import com.google.common.collect.Multimap;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
Expand Down Expand Up @@ -770,32 +771,33 @@ public void list(
List<Component> components = UtilityCommands.entryToComponent(dir, entries, isLoaded,
(name, path, type, loaded) -> {
TextComponentProducer msg = new TextComponentProducer();
String pathArg = StringMan.escape(path);

msg.append(Caption.of("worldedit.schematic.dash.symbol"));

if (loaded) {
msg.append(Caption.of("worldedit.schematic.minus.symbol")
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, unload + " " + path))
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, unload + " " + pathArg))
.hoverEvent(HoverEvent.of(
HoverEvent.Action.SHOW_TEXT,
Caption.of("worldedit.schematic.unload")
)));
} else {
msg.append(Caption.of("worldedit.schematic.plus.symbol")
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadMulti + " " + path))
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadMulti + " " + pathArg))
.hoverEvent(HoverEvent.of(
HoverEvent.Action.SHOW_TEXT,
Caption.of("worldedit.schematic.clipboard")
)));
}
if (type != UtilityCommands.URIType.DIRECTORY) {
msg.append(Caption.of("worldedit.schematic.x.symbol")
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, delete + " " + path))
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, delete + " " + pathArg))
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.delete")))
);
} else if (hasShow) {
msg.append(Caption.of("worldedit.schematic.0.symbol")
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, showCmd + " " + path))
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, showCmd + " " + pathArg))
.hoverEvent(HoverEvent.of(
HoverEvent.Action.SHOW_TEXT,
Caption.of("worldedit.schematic.visualize")
Expand All @@ -804,13 +806,13 @@ public void list(
}
TextComponent msgElem = TextComponent.of(name);
if (type != UtilityCommands.URIType.DIRECTORY) {
msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadSingle + " " + path));
msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadSingle + " " + pathArg));
msgElem = msgElem.hoverEvent(HoverEvent.of(
HoverEvent.Action.SHOW_TEXT,
Caption.of("worldedit.schematic.load")
));
} else {
msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, list + " " + path));
msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, list + " " + pathArg));
msgElem = msgElem.hoverEvent(HoverEvent.of(
HoverEvent.Action.SHOW_TEXT,
Caption.of("worldedit.schematic.list")
Expand Down
Loading