Copilot commented on code in PR #2815:
URL: https://github.com/apache/groovy/pull/2815#discussion_r3809071551


##########
subprojects/groovy-templates/src/test/groovy/groovy/text/MarkupTemplateEngineTest.groovy:
##########
@@ -273,6 +273,71 @@ final class MarkupTemplateEngineTest {
         assert rendered.toString() == '<html><a href=\'foo.html\'>Link 
text</a><tagWithQuote attr=\'fo&apos;o\'/></html>'
     }
 
+    // GROOVY-12278: an attribute value is data, as element text is. yield() 
escapes all five XML
+    // metacharacters; the attribute path escaped only the delimiter in use, 
so an ampersand or
+    // an angle bracket in a value produced markup that is not well formed.

Review Comment:
   This comment says an “angle bracket” in an attribute value makes the markup 
not well formed, but in XML only '<' is not permitted unescaped in attribute 
values; '>' is well-formed. The comment should be tightened to avoid implying 
'>' is invalid.



##########
subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java:
##########
@@ -213,13 +214,54 @@ public BaseTemplate pi(Map<?, ?> attrs) throws 
IOException {
     }
 
     private void writeAttribute(String attName, String value) throws 
IOException {
+        checkAttributeName(attName);
         out.write(attName);
         out.write("=");
         writeQt();
-        out.write(escapeQuotes(value));
+        out.write(escapeAttributeValue(value));
         writeQt();
     }
 
+    /**
+     * Escapes an attribute value: the delimiter in use, which would otherwise 
end the value,
+     * and the characters which are not well formed inside one whichever 
delimiter surrounds it.
+     * The other quote character is left alone, being neither.
+     *

Review Comment:
   The Javadoc claims the escaped characters are "not well formed" inside 
attribute values, but '>' is well-formed in XML attribute values. Since the 
implementation still escapes it (which is fine), the comment should avoid 
stating that it's ill-formed and instead describe it as part of the chosen 
escaping policy.
   
   This issue also appears on line 253 of the same file.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to