-
Notifications
You must be signed in to change notification settings - Fork 53
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
[ggj]fix: handle special characters in string object value #72
Conversation
src/main/java/com/google/api/generator/engine/ast/StringObjectValue.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/api/generator/engine/ast/StringObjectValue.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/api/generator/engine/ast/StringObjectValue.java
Outdated
Show resolved
Hide resolved
src/test/java/com/google/api/generator/engine/ast/StringObjectValueTest.java
Outdated
Show resolved
Hide resolved
…ator-java into fix-string-object
src/main/java/com/google/api/generator/engine/ast/StringObjectValue.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/api/generator/engine/ast/StringObjectValue.java
Outdated
Show resolved
Hide resolved
…ator-java into fix-string-object
src/main/java/com/google/api/generator/engine/ast/StringObjectValue.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/api/generator/engine/ast/StringObjectValue.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/api/generator/engine/escaper/StringValueEscaper.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/api/generator/engine/escaper/StringValueEscaper.java
Outdated
Show resolved
Hide resolved
src/test/java/com/google/api/generator/engine/ast/StringObjectValueTest.java
Show resolved
Hide resolved
…ator-java into fix-string-object
…ator-java into fix-string-object
|
public StringObjectValue build() { | ||
// `\"` is added to the escaped string value for interpreting it correctly in file. | ||
String value = | ||
String.format("\"%s\"", StringValueEscaper.getInstance().escape(autoBuild().value())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of calling autoBuild
twice, what about just using value()
? IIRC we discussed this in a prior review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, we had this discussion, here we cannot use value()
because it's not static, Builder class has static context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One way to avoid calling autoBuild()
twice is to add a "private" value()
method to the Builder class. Please see the other examples in this codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right! Thank you for the advice, also found this doc that illustrate how/why it works. Learned from this PR!
src/main/java/com/google/api/generator/engine/escaper/BUILD.bazel
Outdated
Show resolved
Hide resolved
src/main/java/com/google/api/generator/engine/ast/StringObjectValue.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/api/generator/engine/ast/StringObjectValue.java
Outdated
Show resolved
Hide resolved
return escaper.escape(sourceString); | ||
} | ||
|
||
public static Escaper getInstance() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider whether this method is still needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes! This is basically for wrapping the escape() in as a static method so that we can call it from the static context (class Builder).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please try calling escape()
without getInstance()
and consider whether getInstance()
is still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry if I confused you, but I did try remove the getInstance()
and directly call StringValueEscaper.escape(value)
and it throws error of cannot calling a non-static method from static context.
since the override escape()
is not static.
String value = String.format("\"%s\"", StringValueEscaper.escape(value()));
please LMK if I did something wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this works, thank you!
String value = String.format("\"%s\"", StringValueEscaper.escaper.escape(value()));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TWIL: if the member or constructor is declared private, then access is permitted if and only if it occurs within the body of the top level class that encloses the declaration of the member or constructor.
public StringObjectValue build() { | ||
// `\"` is added to the escaped string value for interpreting it correctly in file. | ||
String value = | ||
String.format("\"%s\"", StringValueEscaper.getInstance().escape(autoBuild().value())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One way to avoid calling autoBuild()
twice is to add a "private" value()
method to the Builder class. Please see the other examples in this codebase.
…ator-java into fix-string-object
…onfig to v0.8.0 (#72) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [com.google.cloud:google-cloud-shared-config](https://togithub.com/googleapis/java-shared-config) | minor | `0.6.0` -> `0.8.0` | --- ### Release Notes <details> <summary>googleapis/java-shared-config</summary> ### [`v0.8.0`](https://togithub.com/googleapis/java-shared-config/blob/master/CHANGELOG.md#​080-httpswwwgithubcomgoogleapisjava-shared-configcomparev070v080-2020-06-10) [Compare Source](https://togithub.com/googleapis/java-shared-config/compare/v0.7.0...v0.8.0) ##### Features - revert "feat: mark auto-value-annotations scope as provided" ([#​154](https://www.github.com/googleapis/java-shared-config/issues/154)) ([88afb4e](https://www.github.com/googleapis/java-shared-config/commit/88afb4e7c57cb6e00929c098135314a926d9da30)) ### [`v0.7.0`](https://togithub.com/googleapis/java-shared-config/blob/master/CHANGELOG.md#​070-httpswwwgithubcomgoogleapisjava-shared-configcomparev060v070-2020-06-10) [Compare Source](https://togithub.com/googleapis/java-shared-config/compare/v0.6.0...v0.7.0) ##### Features - mark auto-value-annotations scope as provided ([#​151](https://www.github.com/googleapis/java-shared-config/issues/151)) ([44ea4cb](https://www.github.com/googleapis/java-shared-config/commit/44ea4cbbf92b4ad35ffaffb7a01a1bce05063daf)) ##### Bug Fixes - lock the google-java-format version used by formatter plugin ([#​149](https://www.github.com/googleapis/java-shared-config/issues/149)) ([d58c054](https://www.github.com/googleapis/java-shared-config/commit/d58c05437a4ea8767db2bebfcc405ec77aeb9705)) </details> --- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#googleapis/java-shared-dependencies).
resolve left comments in #61
more details can be found in the design doc, investigation is appended.