[ 
https://issues.apache.org/jira/browse/GROOVY-12278?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18105731#comment-18105731
 ] 

ASF GitHub Bot commented on GROOVY-12278:
-----------------------------------------

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.





> improve attribute name rendering in templates
> ---------------------------------------------
>
>                 Key: GROOVY-12278
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12278
>             Project: Groovy
>          Issue Type: Improvement
>          Components: groovy-templates
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to