Skip to content

Commit

Permalink
rework name validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed Dec 30, 2024
1 parent 51bc301 commit 8f9bc86
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 1 addition & 5 deletions enigma/src/main/java/org/quiltmc/enigma/api/Enigma.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.quiltmc.enigma.api.class_provider.ObfuscationFixClassProvider;
import org.quiltmc.enigma.api.service.NameProposalService;
import org.quiltmc.enigma.api.service.ReadWriteService;
import org.quiltmc.enigma.api.source.TokenType;
import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
import org.quiltmc.enigma.api.translation.mapping.serde.FileType;
import org.quiltmc.enigma.api.translation.mapping.tree.EntryTree;
Expand Down Expand Up @@ -108,10 +107,7 @@ public EnigmaProject openJar(Path path, ClassProvider libraryClassProvider, Prog

if (proposed != null) {
for (var entry : proposed.entrySet()) {
if (!service.bypassValidation() && entry.getValue() != null && entry.getValue().tokenType() != TokenType.JAR_PROPOSED) {
throw new RuntimeException("Token type of mapping " + entry.getValue() + " for entry " + entry.getKey() + " was " + entry.getValue().tokenType() + ", but should be " + TokenType.JAR_PROPOSED + "!");
}

service.validateProposedMapping(entry.getKey(), entry.getValue());
proposedNames.insert(entry.getKey(), entry.getValue());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,16 @@ default EntryMapping createMapping(String name, TokenType tokenType) {

return new EntryMapping(name, null, tokenType, this.getId());
}
/**
* Validates the provided mapping to ensure it is a valid proposal.
* Do not override this unless you know exactly what you're doing!
*
* @param entry the entry the mapping will be attached to
* @param mapping the mapping to be validated
*/
default void validateProposedMapping(@Nullable Entry<?> entry, @Nullable EntryMapping mapping) {
if (!this.bypassValidation() && mapping != null && mapping.tokenType() != TokenType.JAR_PROPOSED) {
throw new RuntimeException("Token type of mapping " + mapping + " for entry " + entry + " (was " + mapping.tokenType() + ", but should be " + TokenType.JAR_PROPOSED + "!)");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ public void insertDynamicallyProposedMappings(@Nullable Entry<?> obfEntry, @Null
// due to unchecked proposal, proposers are allowed to insert other token types
// when deobfuscated, they must be put in the main tree
proposedNames.forEach((entry, mapping) -> {
service.validateProposedMapping(entry, mapping);

if (mapping.tokenType() == TokenType.DEOBFUSCATED) {
this.mappings.insert(entry, mapping);
} else {
Expand Down

0 comments on commit 8f9bc86

Please sign in to comment.