Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix support for Chinese and other characters in setwarp and sethome filenames; ensure backward compatibility with old safe string names replaced by underscores#5890

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
wkea wants to merge7 commits intoEssentialsX:2.x
base:2.x
Choose a base branch
Loading
fromwkea:2.x
Open
Show file tree
Hide file tree
Changes fromall 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
26 changes: 16 additions & 10 deletionsEssentials/src/main/java/com/earth2me/essentials/UserData.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,10 +143,12 @@ private String getHomeName(String search) {
}
return search;
}

//Optimize character compatibility
public Location getHome(final String name) {
final String search = getHomeName(name);
final LazyLocation loc = holder.homes().get(search);
LazyLocation loc = holder.homes().get(getHomeName(name));
if (loc == null) {
loc = holder.homes().get(getHomeName(StringUtil.safeString(name)));
}
return loc != null ? loc.location() : null;
}

Expand DownExpand Up@@ -179,28 +181,32 @@ public List<String> getHomes() {

public void setHome(String name, final Location loc) {
//Invalid names will corrupt the yaml
name = StringUtil.safeString(name);
name = StringUtil.new_safeString(name);
holder.homes().put(name, LazyLocation.fromLocation(loc));
config.save();
}

public void delHome(final String name) throws Exception {
String search = getHomeName(name);
if (!holder.homes().containsKey(search)) {
search = StringUtil.safeString(search);
}
if (holder.homes().containsKey(search)) {
holder.homes().remove(search);
String safeSearch = StringUtil.new_safeString(search);
String oldSafeSearch = StringUtil.safeString(search);
if (holder.homes().containsKey(safeSearch)) {
holder.homes().remove(safeSearch);
config.save();
} else if (holder.homes().containsKey(oldSafeSearch)) {
holder.homes().remove(oldSafeSearch);
config.save();
} else {
throw new TranslatableException("invalidHome", search);
}
}


public void renameHome(final String name, final String newName) throws Exception {
final LazyLocation location = holder.homes().remove(name);
//If possible, it is necessary to improve the compatibility here to make it support underscores
if (location != null) {
holder.homes().put(StringUtil.safeString(newName), location);
holder.homes().put(StringUtil.new_safeString(newName), location);
config.save();
} else {
throw new TranslatableException("invalidHome", name);
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,7 @@ public Worth(final File dataFolder) {
public BigDecimal getPrice(final IEssentials ess, final ItemStack itemStack) {
BigDecimal result = BigDecimal.ONE.negate();


final String itemname = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");

if (VersionUtil.PRE_FLATTENING) {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

public class Commandhome extends EssentialsCommand {
Expand DownExpand Up@@ -124,7 +125,9 @@ private void goHome(final User user, final User player, final String home, final
if (home.length() < 1) {
throw new NotEnoughArgumentsException();
}
final Location loc = player.getHome(home);

final Location loc = player.getHome(home);

if (loc == null) {
throw new NotEnoughArgumentsException();
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,17 +10,18 @@
import java.util.regex.Pattern;

public final class StringUtil {
private static final PatternINVALIDFILECHARS = Pattern.compile("[^a-z0-9-]");
private static final PatternINVALIDCHARACTER = Pattern.compile("[/\\\\:*?\"<>|\\x00-\\x1F]");
private static final Pattern STRICTINVALIDCHARS = Pattern.compile("[^a-z0-9]");
@SuppressWarnings("CheckStyle")
private static final Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFC]");
private static final Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFD]");


private StringUtil() {
}

//Used to clean file names before saving to disk
public static String sanitizeFileName(final String name) {
returnINVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_");
returnINVALIDCHARACTER.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_");
}

//Used to clean strings/names before saving as filenames/permissions
Expand All@@ -30,6 +31,12 @@ public static String safeString(final String string) {
}
return STRICTINVALIDCHARS.matcher(string.toLowerCase(Locale.ENGLISH)).replaceAll("_");
}
public static String new_safeString(final String string) {
if (string == null) {
return null;
}
return INVALIDCHARACTER.matcher(string.toLowerCase(Locale.ENGLISH)).replaceAll("_");
}

//Less restrictive string sanitizing, when not used as perm or filename
public static String sanitizeString(final String string) {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp