Skip to content

Commit

Permalink
fix: strings only containing ':' being treated as labels
Browse files Browse the repository at this point in the history
  • Loading branch information
jumanji144 committed Jul 28, 2024
1 parent b88d649 commit 511cdb4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private ASTInstruction parseInstruction() {
ctx.throwEofError("instruction argument or label");
return null;
}
if (peek.content().equals(":")) {
if (peek.type() == TokenType.OPERATOR && peek.content().equals(":")) {
ctx.leaveState(State.IN_INSTRUCTION);
ctx.take(":");
return new ASTLabel(new ASTIdentifier(instruction));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package me.darknet.assembler;

import me.darknet.assembler.ast.ASTElement;
import me.darknet.assembler.ast.primitive.ASTArray;
import me.darknet.assembler.ast.primitive.ASTIdentifier;
import me.darknet.assembler.ast.primitive.*;
import me.darknet.assembler.ast.specific.*;
import me.darknet.assembler.error.Error;
import me.darknet.assembler.error.Result;
Expand Down
12 changes: 12 additions & 0 deletions jasm-core/src/test/java/me/darknet/assembler/InstructionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,16 @@ public void testLookupSwitch() {
);
}

@Test
public void testWeirdStrings() {
assertCode(
new String[] { "ldc \":\"" }, BytecodeFormat.JVM, (code) -> {
List<ASTInstruction> instructions = code.instructions();
assertEquals(1, instructions.size());
assertEquals("ldc", instructions.get(0).identifier().content());
assertEquals(":", instructions.get(0).arguments().get(0).content());
}
);
}

}

0 comments on commit 511cdb4

Please sign in to comment.