-
Notifications
You must be signed in to change notification settings - Fork 130
Fix datastore grpc doc class generation for python and ruby #716
Fix datastore grpc doc class generation for python and ruby #716
Conversation
@@ -22,6 +22,8 @@ | |||
|
|||
/** Returns a Sphinx-formatted comment string. */ | |||
public static String sphinxify(String comment) { | |||
// escape '$' in the comment first | |||
comment = comment.replaceAll("\\$", "\\\\\\$"); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -22,6 +22,8 @@ | |||
|
|||
/** Returns a Sphinx-formatted comment string. */ | |||
public static String sphinxify(String comment) { | |||
// escape '$' in the comment first | |||
comment = comment.replaceAll("\\$", "\\\\\\$"); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -22,6 +22,8 @@ | |||
|
|||
/** Returns a Sphinx-formatted comment string. */ | |||
public static String sphinxify(String comment) { | |||
// escape '$' in the comment first |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
public static String rdocify(String comment) { | ||
// escape '$' in the comment first |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Current coverage is 81.36% (diff: 100%)@@ master #716 diff @@
==========================================
Files 292 294 +2
Lines 11117 11190 +73
Methods 0 0
Messages 0 0
Branches 1465 1480 +15
==========================================
+ Hits 9042 9105 +63
- Misses 1673 1680 +7
- Partials 402 405 +3
|
* Use Matcher.quoteReplacement to escape '$' in cloud/absolute link
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.
I think some unit tests would really help clarify what this PROTO_LINK_PATTERN
and these changes are actually doing. I find myself focusing on the details of this PR without really understanding the big picture, and some usage examples would help with that.
@@ -26,6 +26,7 @@ | |||
Pattern.compile("\\[([^\\]]+)\\]\\((\\p{Alpha}+:[^\\)]+)\\)"); | |||
public static final Pattern CLOUD_LINK_PATTERN = | |||
Pattern.compile("\\[([^\\]]+)\\]\\(((?!\\p{Alpha}+:)[^\\)]+)\\)"); | |||
public static final Pattern PROTO_LINK_PATTERN = Pattern.compile("\\[([^\\]]+)\\]\\[[^\\]]*\\]"); | |||
public static final Pattern PROTO_LINK_PATTERN = | |||
Pattern.compile("\\[([^\\]]+)\\]\\[([A-Za-z_][A-Za-z_.0-9]*)*\\]"); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went 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.
It is worth adding a new random comment in the test case to see the behaviors and expected results.
@@ -26,6 +26,7 @@ | |||
Pattern.compile("\\[([^\\]]+)\\]\\((\\p{Alpha}+:[^\\)]+)\\)"); | |||
public static final Pattern CLOUD_LINK_PATTERN = | |||
Pattern.compile("\\[([^\\]]+)\\]\\(((?!\\p{Alpha}+:)[^\\)]+)\\)"); | |||
public static final Pattern PROTO_LINK_PATTERN = Pattern.compile("\\[([^\\]]+)\\]\\[[^\\]]*\\]"); | |||
public static final Pattern PROTO_LINK_PATTERN = | |||
Pattern.compile("\\[([^\\]]+)\\]\\[([A-Za-z_][A-Za-z_.0-9]*)*\\]"); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@jmuk Like fuzzing? |
oh, not saying that random :) I'd like to recommend to copy&paste some comments which causes this problem from the production proto files (or write something by ourselves). |
Got it. SGTM |
@jmuk @bjwatson @geigerj I added unit test cases to test how Python/Ruby/NodeJS CommentFixer should handle '$' to avoid throwing IAE. These are not comprehensive test cases for the CommentFixers, because I think this PR should focus on related problems. I filed #722 to add more comprehensive tests. I think @geigerj understands best for these markdown link requirements, so I assigned it to him. |
@jmuk I updated the description to add more details how this problem is caused. |
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.
Almost done. :)
Truth.assertThat(m.find()).isTrue(); | ||
m = CommentPatterns.PROTO_LINK_PATTERN.matcher("[$Shelf][]"); | ||
Truth.assertThat(m.find()).isTrue(); | ||
m = CommentPatterns.PROTO_LINK_PATTERN.matcher("[][abc]"); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Truth.assertThat(m.find()).isTrue(); | ||
m = CommentPatterns.PROTO_LINK_PATTERN.matcher("[][abc]"); | ||
Truth.assertThat(m.find()).isFalse(); | ||
m = CommentPatterns.PROTO_LINK_PATTERN.matcher("[A-Za-z_$][A-Za-z_$0-9]"); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went 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.
LGTM, although as Brian mentioned, more comments would be nice.
Truth.assertThat(m.find()).isTrue(); | ||
m = CommentPatterns.PROTO_LINK_PATTERN.matcher("[][abc]"); | ||
Truth.assertThat(m.find()).isFalse(); | ||
m = CommentPatterns.PROTO_LINK_PATTERN.matcher("[A-Za-z_$][A-Za-z_$0-9]"); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
OK, makes sense. Comments will help make this clear. On Nov 7, 2016 10:15 AM, "Song Wang" [email protected] wrote:
|
I was thinking of adding comments to library.proto (so that you can make sure everything is fine in the baseline files on every language). It is actually not safe as unit tests you wrote, but it could reveal errors on other languages too. |
If we want to do comprehensive unit test cases and comments, it should be done in #722 separately. |
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.
LGTM, although there is a small typo in one of the comments.
m = CommentPatterns.PROTO_LINK_PATTERN.matcher("[A-Za-z_$][A-Za-z_$0-9]"); | ||
Truth.assertThat(m.find()).isFalse(); | ||
// Fully qualified name many NOT be numbers only |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
#716 This is due to datastore API's GqlQuery message's comment contains '$' so we have to escape it, otherwise it will cause java's regex failure (throwing IAE exception)
In https://github.com/googleapis/googleapis/blob/master/google/datastore/v1/query.proto#L232,
Key must match regex
[A-Za-z_$][A-Za-z_$0-9]*
The original CommentPatterns.PROTO_LINK_PATTERN causes the above [A-Za-z_$][A-Za-z_$0-9] to be parsed as a proto link, using Ruby as an example (similar with Python and NodeJS)
In RDocCommentFixer.java:
When m.appendReplacement is called, the second argument contains a '$' in it (because m.group(1) is A-Za-z_$, so that causes appendReplacement to throw IAE.