Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy task expand() transforms "\n" into newlines #10458

Closed
cdalexndr opened this issue Sep 5, 2019 · 6 comments
Closed

Copy task expand() transforms "\n" into newlines #10458

cdalexndr opened this issue Sep 5, 2019 · 6 comments
Labels
a:bug closed:not-fixed Indicates the issue was not fixed and is not planned to be

Comments

@cdalexndr
Copy link

Consider the input some configuration file that contains the following text in some json:
"SELECT\n count(id) AS idc\nFROM dev.product"

Apply the following copy task with expand:

task copyTest(type: Copy) {
    from 'test'
    into "$buildDir/test"
    expand()
}

The text is transformed into an invalid json:

"SELECT
  count(id) AS idc
FROM dev.product"

Gradle 5.5.1

Build time: 2019-07-10 20:38:12 UTC
Revision: 3245f74

Kotlin: 1.3.31
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.14 compiled on March 12 2019
JVM: 12.0.2 (Oracle Corporation 12.0.2+10)
OS: Windows 10 10.0 amd64

@cdalexndr
Copy link
Author

Workaround: escaped "\\n" string instead of "\n"

@cdalexndr
Copy link
Author

Same behaviour with "\t"

@big-guy
Copy link
Member

big-guy commented Sep 6, 2019

expand() makes Gradle treat every file copied as if it's a template. It's run through Groovy's SimpleTemplateEngine.

If you don't want this behavior for some files, you can exclude them and copy them separately or escape the files (like you found).

@big-guy big-guy closed this as completed Sep 6, 2019
@cdalexndr
Copy link
Author

cdalexndr commented Sep 6, 2019

SimpleTemplateEngine has an option to escape backslashes:
SimpleTemplateEngine.setEscapeBackslash​(boolean escapeBackslash)

Turning on this option fixes my issue: online script
Please provide a method to turn on this option when using expand

@cdalexndr
Copy link
Author

Opened feature request: #10492

@ljacomet
Copy link
Member

While this was closed as "won't fix", the linked issue (#10492) ended up being fixed in 7.2

@ljacomet ljacomet closed this as not planned Won't fix, can't repro, duplicate, stale Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug closed:not-fixed Indicates the issue was not fixed and is not planned to be
Projects
None yet
Development

No branches or pull requests

3 participants