grails-core icon indicating copy to clipboard operation
grails-core copied to clipboard

4.0.4 and onwards encodes HTML tags in codec output, but only when running as jar

Open danduke opened this issue 4 years ago • 15 comments

In summary, grails 4.0.4 codecs that output HTML will do so encoded (so the HTML tags are re-encoded and displayed as tags on the page), but only when running as a jar. Using run-app demonstrates expected behavior.

An example project is here: https://github.com/danduke/encoding-test

Stackoverflow issue with (slightly) more description is here: https://stackoverflow.com/questions/68911681/gsp-encoding-no-longer-working-in-grails-4-0-11

This is a breaking change for upgrading past 4.0.3, since it affects the output of existing codecs and does not respect configuration settings that were used in 4.0.3. I could not find any mention of new configuration changes in the release notes, but if this is fixable by configuration item, that seems reasonable.

danduke avatar Aug 24 '21 20:08 danduke

After reading through a lot of code I'm completely unfamiliar with, this feels like it may be related to changes to GSP precompilation in 4.0.4. This would explain the run-app vs jar difference (I think?) as well.

Perhaps the default codec options aren't passed to the forked process properly?

danduke avatar Aug 25 '21 14:08 danduke

Hi @danduke Your sample app doesn't produce a jar?

% sdk use grails 4.0.4
% git clone https://github.com/danduke/encoding-test
% grails clean
% grails assemble
% find .|grep jar     
./gradle/wrapper/gradle-wrapper.jar
./grails-wrapper.jar

codeconsole avatar Sep 08 '21 19:09 codeconsole

I have removed the apply plugin: war from my build.gradle so the default archive is now jar. Alternatively, you could run gradlew bootJar.

danduke avatar Sep 08 '21 19:09 danduke

I was able to replicate your issue, but only after adding a booJar config. I'd recommend trying to get your example app as specific and ready as possible, then replicating the issue following your instructions. Otherwise, your issue could get overlooked.

% sdk use grails 4.0.4
% git clone https://github.com/danduke/encoding-test
% ./gradlew bootJar  
BUILD SUCCESSFUL in 8s
7 actionable tasks: 5 executed, 2 up-to-date
% ./build/libs/encoding-test-0.1.jar
zsh: permission denied: ./build/libs/encoding-test-0.1.jar
% chmod +x ./build/libs/encoding-test-0.1.jar
% ./build/libs/encoding-test-0.1.jar
zsh: exec format error: ./build/libs/encoding-test-0.1.jar

I believe you need to add the following to your build.gradle

bootJar {
    launchScript()
}

codeconsole avatar Sep 08 '21 20:09 codeconsole

I understand your point, but my preference in reporting issues is to keep them as simple as possible so that there's less confusion about what may be causing the issue.

With the code as-is, this is reproducible (using sdk, or command line installation, or your preference):

grails clean
grails assemble
java -jar build/libs/encoding-test-0.1.jar

Switch gradle.properties from grails 4.0.3 to 4.0.4 to test different versions, as described in the README.md.

danduke avatar Sep 08 '21 20:09 danduke

ah, makes sense. I forgot about running jars the old fashion way ;P

codeconsole avatar Sep 09 '21 16:09 codeconsole

I have confirmed that compiled gsp's have my specified value for

public static final java.lang.String EXPRESSION_CODEC = "whatever I provide";

in 4.0.3, and always

public static final java.lang.String EXPRESSION_CODEC = "html";

in 4.0.4. I can't find a way to work around this. Anyone with more gsp precompilation knowledge have any suggestions for a workaround until the issue is actually resolved?

danduke avatar Sep 21 '21 20:09 danduke

Prob wouldn't hurt to compare the differences between 4.0.3 and 4.0.4 to identify which dependency is causing the issue.
It shouldn't be that difficult being that there are not a lot of differences between 4.0.3 and 4.0.4 https://github.com/grails/grails-core/compare/v4.0.3..v4.0.4

I had an issue with an updating hibernate plugin causing some pages to render as xhtml. If I put the older version of the plugin, it allowed me to run the latest version.

I suspect in my case that it has to do with a change class loading order. I wonder if what you are experiencing is something similar. https://github.com/grails/gorm-hibernate5/issues/303

Actually, I just ended up rolling back 1 change in the plugin and I run the latest plugin as well.

codeconsole avatar Sep 21 '21 21:09 codeconsole

Unfortunately it seems to be in the gsp version difference, but that is so tied to many other dependencies that it's difficult to isolate. At the very least, it does not seem feasible to run later versions of grails with an older version of gsp.

danduke avatar Sep 22 '21 16:09 danduke

Looks like gspVersion changed from 4.0.0 to 4.0.2

https://github.com/grails/grails-gsp/compare/v4.0.0..v4.0.2

Have you tried forcing the use of gspVersion=4.0.0 using a newer version of grails?

codeconsole avatar Sep 22 '21 17:09 codeconsole

Assuming gradle.properties is the right place for that, then yes I have tried it. However, even with this set, a dependency-report still shows org.grails:grails-web-gsp:4.0.2 by way of org.grails:grails-web:4.0.4. I have tried forcing certain plugin versions as well but mostly just end up with compilation failures. Eventually, it comes down to the fact that grails core is expecting GroovyPageCompilerForkTask for gsp compilation, and that's not present until the latest gsp version.

danduke avatar Sep 22 '21 17:09 danduke

Yeah, I just noticed that. GroovyPageCompilerForkTask was created in 4.0.2 which was released with 4.0.4

codeconsole avatar Sep 22 '21 17:09 codeconsole

This was resolved a few grails 4 releases later. I'll check the version

davydotcom avatar Sep 22 '21 18:09 davydotcom

I tried this in 4.0.12, and worked backwards until identifying that it was introduced in 4.0.4.

danduke avatar Sep 22 '21 18:09 danduke

We ran into the same issue. After a lot of searching we found that the problem lies within the new GroovyPageCompilerForkTask.groovy introduced in grails-gsp v4.0.1 in line 66.

https://github.com/grails/grails-gsp/blob/420a86348a4e52693e7ad72bcb354a12831117d5/grails-web-gsp/src/main/groovy/org/grails/web/pages/GroovyPageCompilerForkTask.groovy#L66

Here the config paths are mangled because String instead of String[] is used. A fix for this is present in grails 5.1.0:

https://github.com/grails/grails-gsp/commit/613925c3309f95b5eec3971f205f07c32f0e22b6

If you need to use grails v4.0.4 - v4.0.13 you can use a workaround until its fixed. For that we grabbed the grails-gsp v4.0.3 repository and modified GroovyPageCompilerForkTask.groovy locally according to the v5.1.0 fix and build the jar via gradle. Then we placed the resulting grails-web-gsp-4.0.3.jar in a libs folder in our project modified the build.gradle to use the local version:

configurations {
    all {
        exclude group: 'org.grails.grails-gsp', module: 'grails-web-gsp'
    }
}
...
dependencies {
    ...
    compile "org.grails.plugins:gsp"
    compile files('libs/grails-web-gsp-4.0.3.jar')
    ...
}```

ascheidmeir avatar Apr 12 '22 10:04 ascheidmeir