[ https://issues.apache.org/jira/browse/GROOVY-11314?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17818281#comment-17818281 ]
ASF GitHub Bot commented on GROOVY-11314: ----------------------------------------- codecov-commenter commented on PR #2059: URL: https://github.com/apache/groovy/pull/2059#issuecomment-1951200981 ## [Codecov](https://app.codecov.io/gh/apache/groovy/pull/2059?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report All modified and coverable lines are covered by tests :white_check_mark: > Comparison is base [(`2bd36e5`)](https://app.codecov.io/gh/apache/groovy/commit/2bd36e5d5a9499c1b61902923034f940b0d3be17?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 68.5346% compared to head [(`22d2b9b`)](https://app.codecov.io/gh/apache/groovy/pull/2059?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 68.5304%. <details><summary>Additional details and impacted files</summary> [](https://app.codecov.io/gh/apache/groovy/pull/2059?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) ```diff @@ Coverage Diff @@ ## master #2059 +/- ## ================================================== - Coverage 68.5346% 68.5304% -0.0041% + Complexity 29180 29179 -1 ================================================== Files 1422 1422 Lines 113496 113497 +1 Branches 19548 19548 ================================================== - Hits 77784 77780 -4 - Misses 29175 29177 +2 - Partials 6537 6540 +3 ``` | [Files](https://app.codecov.io/gh/apache/groovy/pull/2059?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | | |---|---|---| | [...ovy-json/src/main/java/groovy/json/JsonOutput.java](https://app.codecov.io/gh/apache/groovy/pull/2059?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWpzb24vc3JjL21haW4vamF2YS9ncm9vdnkvanNvbi9Kc29uT3V0cHV0LmphdmE=) | `95.5882% <100.0000%> (+0.0658%)` | :arrow_up: | ... and [3 files with indirect coverage changes](https://app.codecov.io/gh/apache/groovy/pull/2059/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) </details> > JsonOutput Pretty Print always escapes characters > ------------------------------------------------- > > Key: GROOVY-11314 > URL: https://issues.apache.org/jira/browse/GROOVY-11314 > Project: Groovy > Issue Type: Wish > Components: JSON > Affects Versions: 2.5.23, 3.0.20, 4.0.18 > Reporter: Denis Jakupovic > Assignee: Paul King > Priority: Major > > Hi, > the groovy.json package is widely used. > [https://github.com/apache/groovy/blob/master/subprojects/groovy-json/src/main/java/groovy/json/JsonOutput.java] > > If we use the toPrettyString function the json is being escaped. > {code:java} > JsonBuilder Class: > public String toPrettyString() { > return JsonOutput.prettyPrint(toString()); > } {code} > However, we can construct a JsonBuilder with JsonGenerator and > disableUnicodeEscaping and use new JsonBuilder(content, generator).toString() > to create a proper json string representation. This is not possible with > JsonOutput though because there is a final constructor and uses a default > generator. However disableUnicodeEscaping is true by default but it is not > handled properly by the JsonOutput class. It would be great if the JsonOutput > had the same feature to construct JsonOutput with a custom JsonGenerator. The > JsonOutput object uses the DefaultJsonGenerator with enabled unicode escaping > through Options but the toJson() and prettyPrint methods do not handle the > escaping properly. > [https://github.com/apache/groovy/blob/GROOVY_3_0_X/subprojects/groovy-json/src/main/java/groovy/json/JsonOutput.java#L209|https://github.com/apache/groovy/blob/GROOVY_3_0_X/subprojects/groovy-json/src/main/java/groovy/json/JsonOutput.java#L162] > {code:java} > case STRING: > String textStr = token.getText(); > String textWithoutQuotes = textStr.substring(1, textStr.length() - 1); > if (textWithoutQuotes.length() > 0) { > output.addJsonEscapedString(textWithoutQuotes); > } else { > output.addQuoted(Chr.array()); > } > break; {code} > And here: > [https://github.com/apache/groovy/blob/master/subprojects/groovy-json/src/main/java/org/apache/groovy/json/internal/CharBuf.java#L379] > {code:java} > public final CharBuf addJsonEscapedString(final char[] charArray, boolean > disableUnicodeEscaping) { > if (charArray.length == 0) return this; > if (hasAnyJSONControlChars(charArray, disableUnicodeEscaping)) { > return doAddJsonEscapedString(charArray, disableUnicodeEscaping); > } else { > return this.addQuoted(charArray); > } > } {code} > *If the JsonBuilder is constructed with a JsonGenerator it should be > constructed with JsonOuput as well and the prettyPrint and toJson function > shall not add escaped strings.* *The Bug is in JsonOutput in the CharBuf > call.* > This has to be fixed for toPretty method: > {code:java} > case STRING: > String textStr = token.getText(); > String textWithoutQuotes = textStr.substring(1, textStr.length() - 1); > if (textWithoutQuotes.length() > 0) { > output.addJsonEscapedString(textWithoutQuotes, disableUnicodeEscaping); > } else { > output.addQuoted(Chr.array()); > } > break; {code} > output.addJsonEscapedString(textWithoutQuotes, disableUnicodeEscaping) should > be called with disableUnicodeEscaping. > Currently there is no way to prettyPrint a json with the groovy.json classes > without having escaped characters in the generated json. > Best > Denis -- This message was sent by Atlassian Jira (v8.20.10#820010)