Skip to content

Commit 212dc02

Browse files
committed
feat: LuacageDatabaseGenerator will check package name
1 parent 2e9860b commit 212dc02

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/java/org/eu/smileyik/luaInMinecraftBukkitII/tools/LuacageDatabaseGenerator.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
public class LuacageDatabaseGenerator {
3636

3737
public static final String BUILD_PATH = System.getenv("luainminecraftbukkit_luacage_build");
38+
private static final String NAME_PATTERN = "[a-zA-Z][a-zA-Z0-9_-]+";
3839

3940
public static void run() {
4041
if (BUILD_PATH == null) return;
@@ -127,6 +128,9 @@ public static void generateMetaList(String repoPath, String outPath) {
127128
}
128129

129130
public static void updateMetaList(String repoPath, String outPath, String name) throws Exception {
131+
if (!name.matches(NAME_PATTERN)) {
132+
throw new Exception("Invalid name " + name + ", name not matches pattern " + NAME_PATTERN);
133+
}
130134
File repo = new File(repoPath);
131135
File pkgDir = new File(repoPath, PACKAGE_DIR_NAME);
132136
List<LuacageJsonMeta> database = getDatabase(repo);
@@ -221,12 +225,13 @@ private static List<LuacageJsonMeta> getDatabase(File repo) throws FileNotFoundE
221225
private static void writeJson(List<LuacageJsonMeta> list, String outPath) throws IOException, NoSuchAlgorithmException {
222226
list.sort(Comparator.comparing(LuacageCommonMeta::getName));
223227
String json = new Gson().toJson(list);
224-
Files.write(Paths.get(outPath), json.getBytes(StandardCharsets.UTF_8),
228+
Path path = Paths.get(outPath);
229+
Files.write(path, json.getBytes(StandardCharsets.UTF_8),
225230
StandardOpenOption.WRITE,
226231
StandardOpenOption.TRUNCATE_EXISTING,
227232
StandardOpenOption.CREATE
228233
);
229-
String hash = HashUtil.sha256(Paths.get(outPath).toFile());
234+
String hash = HashUtil.sha256(path.toFile());
230235
Files.write(Paths.get(outPath + ".hash"), hash.getBytes(StandardCharsets.UTF_8),
231236
StandardOpenOption.WRITE,
232237
StandardOpenOption.TRUNCATE_EXISTING,

0 commit comments

Comments
 (0)