Skip to content

Commit

Permalink
Ignore commas in taglib attributes. Fixes #25
Browse files Browse the repository at this point in the history
  • Loading branch information
ilopmar committed Jun 4, 2018
1 parent af8bfeb commit 410b2b7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions grails-gsp/src/main/groovy/org/grails/gsp/GroovyPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ public JspTag getJspTag(String uri, String name) {
public final void invokeTag(String tagName, String tagNamespace, int lineNumber, Map attrs, int bodyClosureIndex) {
Closure body = getBodyClosure(bodyClosureIndex);

// See https://github.com/grails/grails-gsp/issues/25
Map cleanedAttrs = new LinkedHashMap();
for (Object o : attrs.entrySet()) {
Map.Entry<String, ?> entry = (Map.Entry) o;
String newKey = entry.getKey().replaceAll(",", "").trim();
cleanedAttrs.put(newKey, entry.getValue());
}
attrs = cleanedAttrs;

// TODO custom namespace stuff needs to be generalized and pluggable
if (tagNamespace.equals(TEMPLATE_NAMESPACE) || tagNamespace.equals(LINK_NAMESPACE)) {
final String tmpTagName = tagName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.grails.web.taglib

import grails.artefact.Artefact
import grails.test.mixin.TestFor
import spock.lang.Specification

@TestFor(ConcatTagLib)
class RemoveCommaFromArgumentsTagLibTests extends Specification {

void 'test invoke tag lib with multiple params with commas'() {
expect:
applyTemplate('<g:concatAllAttrsKeys one="1" two="2", three="3" four="4" five="5" />') == 'onetwothreefourfive'

and:
applyTemplate('<g:concatAllAttrsValues one="1" two="2", three="3" four="4" five="5" />') == '12345'
}
}

@Artefact('TagLib')
class ConcatTagLib {
Closure concatAllAttrsKeys = { attrs, body ->
attrs.each { attr ->
out << attr.key
}
}

Closure concatAllAttrsValues = { attrs, body ->
attrs.each { attr ->
out << attr.value
}
}
}

0 comments on commit 410b2b7

Please sign in to comment.