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

Gradle init doesn't escape single quotes #20981

Closed
otrosien opened this issue Jun 10, 2022 · 3 comments · Fixed by #20993
Closed

Gradle init doesn't escape single quotes #20981

otrosien opened this issue Jun 10, 2022 · 3 comments · Fixed by #20993
Assignees
Milestone

Comments

@otrosien
Copy link

otrosien commented Jun 10, 2022

When using gradle init (with default settings / groovy output) to convert a maven-based project to gradle, I noticed that, when the name property in pom.xml contains a single quote, it produces an invalid line in build.gradle.

Expected Behavior

gradle should ensure escaping of single-quotes when copying over strings from pom.xml to build.gradle

Current Behavior

pom.xml:    <name>That's it</name>
build.gradle:description = 'That's it'

Worth noting that with kotlin output the same lack of escaping happens for double-quotes.

Steps to Reproduce

POC repository: https://github.com/otrosien/gradle-init-bug-poc

Your Environment

------------------------------------------------------------
Gradle 7.4.2
------------------------------------------------------------

Build time:   2022-03-31 15:25:29 UTC
Revision:     540473b8118064efcc264694cbcaa4b677f61041

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.3 (Eclipse Adoptium 17.0.3+7)
OS:           Mac OS X 12.3.1 x86_64
@h0tk3y h0tk3y added in:build-init-plugin 🌱 internal-onboarding Good issues to onboard new Gradle team members and removed to-triage labels Jun 10, 2022
@tbroadley
Copy link
Contributor

I can try to fix this 🙂

@otrosien
Copy link
Author

I can try to fix this 🙂

nice one. 👍🏼

@abstratt abstratt added this to the 7.6 RC1 milestone Jul 11, 2022
bot-gradle added a commit that referenced this issue Jul 11, 2022
<!--- The issue this PR addresses -->
Fixes #20981

### Context
<!--- Why do you believe many users will benefit from this change? -->
<!--- Link to relevant issues or forum discussions here -->
Currently, the gradle init command doesn't escape quotes in literal
strings (e.g. the value of the description field) in generated
build.gradle.kts files. This commit causes Gradle to correctly escape
quotes in these strings (single quotes when generating Groovy and double
quotes for Kotlin).

### Contributor Checklist
- [x] [Review Contribution Guidelines](https://github.com/gradle/gradle/blob/master/CONTRIBUTING.md)
- [x] Make sure that all commits are [signed off](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---signoff) to indicate that you agree to the terms of [Developer Certificate of Origin](https://developercertificate.org/).
- [x] Make sure all contributed code can be distributed under the terms of the [Apache License 2.0](https://github.com/gradle/gradle/blob/master/LICENSE), e.g. the code was written by yourself or the original code is licensed under [a license compatible to Apache License 2.0](https://apache.org/legal/resolved.html).
- [x] Check ["Allow edit from maintainers" option](https://help.github.com/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork/) in pull request so that additional changes can be pushed by Gradle team
- [x] Provide integration tests (under `<subproject>/src/integTest`) to verify changes from a user perspective
- [x] Provide unit tests (under `<subproject>/src/test`) to verify logic
- [x] Update User Guide, DSL Reference, and Javadoc for public-facing changes
- [x] Ensure that tests pass sanity check: `./gradlew sanityCheck`
- [x] Ensure that tests pass locally: `./gradlew <changed-subproject>:quickTest`

### Gradle Core Team Checklist
- [x] Verify design and implementation
- [x] Verify test coverage and CI build status
- [x] Verify documentation
- [x] Recognize contributor in release notes

Co-authored-by: Thomas Broadley <buriedunderbooks@hotmail.com>
@otrosien
Copy link
Author

@tbroadley thanks again for the code contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants