From 410b2b72e1a131522b0bc5203abc2d2f1c4da775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20L=C3=B3pez?= Date: Mon, 4 Jun 2018 15:30:39 +0200 Subject: [PATCH] Ignore commas in taglib attributes. Fixes #25 --- .../groovy/org/grails/gsp/GroovyPage.java | 9 ++++++ ...RemoveCommaFromArgumentsTagLibTests.groovy | 32 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 grails-plugin-gsp/src/test/groovy/org/grails/web/taglib/RemoveCommaFromArgumentsTagLibTests.groovy diff --git a/grails-gsp/src/main/groovy/org/grails/gsp/GroovyPage.java b/grails-gsp/src/main/groovy/org/grails/gsp/GroovyPage.java index ccb6861b9a..44020e6156 100644 --- a/grails-gsp/src/main/groovy/org/grails/gsp/GroovyPage.java +++ b/grails-gsp/src/main/groovy/org/grails/gsp/GroovyPage.java @@ -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 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; diff --git a/grails-plugin-gsp/src/test/groovy/org/grails/web/taglib/RemoveCommaFromArgumentsTagLibTests.groovy b/grails-plugin-gsp/src/test/groovy/org/grails/web/taglib/RemoveCommaFromArgumentsTagLibTests.groovy new file mode 100644 index 0000000000..2e88818c8e --- /dev/null +++ b/grails-plugin-gsp/src/test/groovy/org/grails/web/taglib/RemoveCommaFromArgumentsTagLibTests.groovy @@ -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('') == 'onetwothreefourfive' + + and: + applyTemplate('') == '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 + } + } +}