This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git

commit ca81739ee027dc91a645dbcb1bb2e7614db23a4f
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Nov 20 11:31:48 2026 -0500

    Sort members
---
 .../org/apache/bcel/classfile/AttributeTest.java   | 20 +++---
 .../org/apache/bcel/util/Class2HTMLXSSTest.java    | 80 +++++++++++-----------
 2 files changed, 50 insertions(+), 50 deletions(-)

diff --git a/src/test/java/org/apache/bcel/classfile/AttributeTest.java 
b/src/test/java/org/apache/bcel/classfile/AttributeTest.java
index f8ca7766..5cb3a573 100644
--- a/src/test/java/org/apache/bcel/classfile/AttributeTest.java
+++ b/src/test/java/org/apache/bcel/classfile/AttributeTest.java
@@ -73,6 +73,16 @@ public class AttributeTest {
         assertThrows(ClassFormatException.class, () -> 
Attribute.readAttribute(dataInput, constantPool));
     }
 
+    /**
+     * Preserves the standard names at both ends of the known-tag range even 
when the constant-pool name differs.
+     */
+    @Test
+    public void testToStringForKnownTags() {
+        final ConstantPool constantPool = new ConstantPool(new Constant[] { 
null, new ConstantUtf8("DifferentName") });
+        assertEquals("SourceFile", new TestAttribute(Const.ATTR_SOURCE_FILE, 
1, 0, constantPool).toString());
+        assertEquals("RuntimeInvisibleTypeAnnotations", new 
TestAttribute(Const.ATTR_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, 1, 0, 
constantPool).toString());
+    }
+
     /**
      * Formats a custom attribute parsed through a registered reader without 
requiring a subclass {@code toString()} override.
      * <p>
@@ -103,16 +113,6 @@ public class AttributeTest {
         }
     }
 
-    /**
-     * Preserves the standard names at both ends of the known-tag range even 
when the constant-pool name differs.
-     */
-    @Test
-    public void testToStringForKnownTags() {
-        final ConstantPool constantPool = new ConstantPool(new Constant[] { 
null, new ConstantUtf8("DifferentName") });
-        assertEquals("SourceFile", new TestAttribute(Const.ATTR_SOURCE_FILE, 
1, 0, constantPool).toString());
-        assertEquals("RuntimeInvisibleTypeAnnotations", new 
TestAttribute(Const.ATTR_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, 1, 0, 
constantPool).toString());
-    }
-
     /**
      * Uses the declared name for negative tags, including {@link 
Const#ATTR_UNKNOWN}, and tags above the standard-name table.
      *
diff --git a/src/test/java/org/apache/bcel/util/Class2HTMLXSSTest.java 
b/src/test/java/org/apache/bcel/util/Class2HTMLXSSTest.java
index 3899a1f8..e32c741a 100644
--- a/src/test/java/org/apache/bcel/util/Class2HTMLXSSTest.java
+++ b/src/test/java/org/apache/bcel/util/Class2HTMLXSSTest.java
@@ -94,46 +94,6 @@ class Class2HTMLXSSTest {
         assertTrue(methods.contains("x&quot; onmouseover"), "expected quotes 
in the field name to be escaped");
     }
 
-    /**
-     * Tests that unknown method attribute descriptions are HTML-escaped.
-     *
-     * <p>
-     * Attribute names come from attacker-controlled {@code CONSTANT_Utf8} 
entries and may contain HTML metacharacters. This is a regression for an
-     * escaping omission in the earlier fix for CVE-2026-105111.
-     * </p>
-     */
-    @ParameterizedTest
-    @CsvSource({
-        "0, ''",
-        "1, ': 00'",
-        "10, ': 00 00 00 00 00 00 00 00 00 00'",
-        "11, ': 00 00 00 00 00 00 00 00 00 00... (truncated)'"
-    })
-    void testUnknownMethodAttributeNameIsEscaped(final int length, final 
String expectedPayload, @TempDir final Path outputDir) throws Exception {
-        final ClassGen cg = new ClassGen("EvilUnknownAttr", 
"java.lang.Object", "EvilUnknownAttr.java", Const.ACC_PUBLIC, null);
-        final ConstantPoolGen cpg = cg.getConstantPool();
-        final String marker = "x<svg onload=\"alert(1)\">&'\"y";
-        final int nameIndex = cpg.addUtf8(marker);
-        final InstructionList instructions = new InstructionList();
-        instructions.append(InstructionConst.ICONST_0);
-        instructions.append(InstructionConst.IRETURN);
-        final MethodGen mg = new MethodGen(Const.ACC_PUBLIC | 
Const.ACC_STATIC, Type.INT, Type.NO_ARGS, null, "value", "EvilUnknownAttr", 
instructions, cpg);
-        mg.addAttribute(new Unknown(nameIndex, length, new byte[length], 
cpg.getConstantPool()));
-        mg.setMaxStack();
-        mg.setMaxLocals();
-        cg.addMethod(mg.getMethod());
-        instructions.dispose();
-
-        final JavaClass jc = new ClassParser(new 
ByteArrayInputStream(cg.getJavaClass().getBytes()), 
"EvilUnknownAttr.class").parse();
-        assertNotNull(jc.getMethods()[0].getCode(), "expected the parsed 
method to retain its Code attribute");
-        new Class2HTML(jc, outputDir.toAbsolutePath() + File.separator);
-
-        final String code = new 
String(Files.readAllBytes(outputDir.resolve("EvilUnknownAttr_code.html")), 
StandardCharsets.UTF_8);
-        assertFalse(code.contains("<svg"), "unknown attribute name was emitted 
as a live HTML element");
-        assertTrue(code.contains("<LI>(Unknown attribute x&lt;svg 
onload=&quot;alert(1)&quot;&gt;&amp;&#39;&quot;y" + expectedPayload + ")</LI>"),
-            "expected the complete unknown attribute description to be 
HTML-escaped");
-    }
-
     /**
      * Tests that an unknown code-level attribute description is shown with 
its actual (escaped) name.
      *
@@ -177,4 +137,44 @@ class Class2HTMLXSSTest {
         assertTrue(codeHtml.contains("<LI>(Unknown attribute 
x&lt;script&gt;alert(1)&lt;/script&gt;)</LI>"),
             "expected the unknown code attribute description to be 
HTML-escaped");
     }
+
+    /**
+     * Tests that unknown method attribute descriptions are HTML-escaped.
+     *
+     * <p>
+     * Attribute names come from attacker-controlled {@code CONSTANT_Utf8} 
entries and may contain HTML metacharacters. This is a regression for an
+     * escaping omission in the earlier fix for CVE-2026-105111.
+     * </p>
+     */
+    @ParameterizedTest
+    @CsvSource({
+        "0, ''",
+        "1, ': 00'",
+        "10, ': 00 00 00 00 00 00 00 00 00 00'",
+        "11, ': 00 00 00 00 00 00 00 00 00 00... (truncated)'"
+    })
+    void testUnknownMethodAttributeNameIsEscaped(final int length, final 
String expectedPayload, @TempDir final Path outputDir) throws Exception {
+        final ClassGen cg = new ClassGen("EvilUnknownAttr", 
"java.lang.Object", "EvilUnknownAttr.java", Const.ACC_PUBLIC, null);
+        final ConstantPoolGen cpg = cg.getConstantPool();
+        final String marker = "x<svg onload=\"alert(1)\">&'\"y";
+        final int nameIndex = cpg.addUtf8(marker);
+        final InstructionList instructions = new InstructionList();
+        instructions.append(InstructionConst.ICONST_0);
+        instructions.append(InstructionConst.IRETURN);
+        final MethodGen mg = new MethodGen(Const.ACC_PUBLIC | 
Const.ACC_STATIC, Type.INT, Type.NO_ARGS, null, "value", "EvilUnknownAttr", 
instructions, cpg);
+        mg.addAttribute(new Unknown(nameIndex, length, new byte[length], 
cpg.getConstantPool()));
+        mg.setMaxStack();
+        mg.setMaxLocals();
+        cg.addMethod(mg.getMethod());
+        instructions.dispose();
+
+        final JavaClass jc = new ClassParser(new 
ByteArrayInputStream(cg.getJavaClass().getBytes()), 
"EvilUnknownAttr.class").parse();
+        assertNotNull(jc.getMethods()[0].getCode(), "expected the parsed 
method to retain its Code attribute");
+        new Class2HTML(jc, outputDir.toAbsolutePath() + File.separator);
+
+        final String code = new 
String(Files.readAllBytes(outputDir.resolve("EvilUnknownAttr_code.html")), 
StandardCharsets.UTF_8);
+        assertFalse(code.contains("<svg"), "unknown attribute name was emitted 
as a live HTML element");
+        assertTrue(code.contains("<LI>(Unknown attribute x&lt;svg 
onload=&quot;alert(1)&quot;&gt;&amp;&#39;&quot;y" + expectedPayload + ")</LI>"),
+            "expected the complete unknown attribute description to be 
HTML-escaped");
+    }
 }

Reply via email to