Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

GRAILS-7229 - fix issue parsing tag attributes which have a value whi…

…ch contains an equal sign followed by a quote or a double quote. under certain circumstances, that was breaking the parser.
  • Loading branch information...
commit 91371ea99787660200a76fa31eb97fd325be7332 1 parent 6219abd
@jeffbrown jeffbrown authored
View
25 grails-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/taglib/LinkRenderingTagLibTests.groovy
@@ -36,6 +36,31 @@ class TestUrlMappings {
grailsApplication.addArtefact(UrlMappingsArtefactHandler.TYPE, mappingClass)
}
+ void testLinkTagWithAttributeValueContainingEqualSignFollowedByQuote() {
+ // Some of these tests look peculiar but they relate to
+ // scenarios that were broken before GRAILS-7229 was addressed
+
+ def template = '''<g:link controller="demo" class="${(y == '5' && x == '4') ? 'A' : 'B'}" >demo</g:link>'''
+ assertOutputEquals '<a href="/demo" class="B">demo</a>', template, [x: '7', x: '4']
+ template = '''<g:link controller="demo" class="${(y == '5' && x == '4') ? 'A' : 'B'}" >demo</g:link>'''
+ assertOutputEquals '<a href="/demo" class="A">demo</a>', template, [x: '4', y: '5']
+
+ template = '''<g:link controller="demo" class='${(y == "5" && x == "5") ? "A" : "B"}' >demo</g:link>'''
+ assertOutputEquals '<a href="/demo" class="B">demo</a>', template, [y: '0', x: '5']
+ template = '''<g:link controller="demo" class='${(y == "5" && x == "5") ? "A" : "B"}' >demo</g:link>'''
+ assertOutputEquals '<a href="/demo" class="A">demo</a>', template, [y: '5', x: '5']
+
+ template = '''<g:link controller="demo" class="${(someVar == 'abcd')}" >demos</g:link>'''
+ assertOutputEquals '<a href="/demo" class="false">demos</a>', template, [someVar: 'some value']
+ template = '''<g:link controller="demo" class="${(someVar == 'abcd')}" >demos</g:link>'''
+ assertOutputEquals '<a href="/demo" class="true">demos</a>', template, [someVar: 'abcd']
+
+ template = '''<g:link controller="demo" class="${(someVar == 'abcd' )}" >demos</g:link>'''
+ assertOutputEquals '<a href="/demo" class="false">demos</a>', template, [someVar: 'some value']
+ template = '''<g:link controller="demo" class="${(someVar == 'abcd' )}" >demos</g:link>'''
+ assertOutputEquals '<a href="/demo" class="true">demos</a>', template, [someVar: 'abcd']
+ }
+
void testOverlappingReverseMappings() {
def template = '<g:link controller="searchable" action="index" >Search</g:link>'
assertOutputEquals('<a href="/searchable">Search</a>', template)
View
21 grails-web/src/main/groovy/org/codehaus/groovy/grails/web/pages/GroovyPageParser.java
@@ -53,10 +53,8 @@
private static final Pattern ROW_BREAK = Pattern.compile(
"((/td>\\s*</tr>\\s*<)?tr[^>]*>\\s*<)?td[^>]*>",
Pattern.CASE_INSENSITIVE);
- private static final Pattern PARSE_TAG_FIRST_PASS = Pattern.compile(
- "(\\s*(\\S+)\\s*=\\s*[\"]([^\"]*)[\"][\\s|>]{1}){1}");
- private static final Pattern PARSE_TAG_SECOND_PASS = Pattern.compile(
- "(\\s*(\\S+)\\s*=\\s*[']([^']*)['][\\s|>]{1}){1}");
+ private static final Pattern TAG_ATTRIBUTE_PATTERN = Pattern.compile(
+ "(\\s*(\\S+)\\s*=\\s*([\"]([^\"]*)[\"]|[']([^']*)['])[\\s|>]{1}){1}");
private static final Pattern PAGE_DIRECTIVE_PATTERN = Pattern.compile(
"(\\w+)\\s*=\\s*\"([^\"]*)\"");
@@ -1144,18 +1142,13 @@ private void flushBufferedWhiteSpace() {
private void populateMapWithAttributes(Map<String, String> attrs, String attrTokens) {
// do first pass parse which retrieves double quoted attributes
- Matcher m = PARSE_TAG_FIRST_PASS.matcher(attrTokens);
- populateAttributesFromMatcher(m, attrs);
-
- // do second pass parse which retrieves single quoted attributes
- m = PARSE_TAG_SECOND_PASS.matcher(attrTokens);
- populateAttributesFromMatcher(m, attrs);
- }
-
- private void populateAttributesFromMatcher(Matcher m, Map<String, String> attrs) {
+ Matcher m = TAG_ATTRIBUTE_PATTERN.matcher(attrTokens);
while (m.find()) {
String name = m.group(2);
- String val = m.group(3);
+ String val = m.group(4);
+ if(val == null) {
+ val = m.group(5);
+ }
name = '\"' + name + '\"';
if (val.startsWith("${") && val.endsWith("}") && val.indexOf("${", 2)==-1) {
val = val.substring(2, val.length() - 1);
Please sign in to comment.
Something went wrong with that request. Please try again.