Skip to content

Commit

Permalink
fix expansion of strings containing references to capture groups (#1038)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-brice-jaglin authored Jan 19, 2021
1 parent d443601 commit 4003e62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private[compiler] object FieldTransformations {
val matcher = pattern.matcher(templateText)
val result = new StringBuffer()
while (matcher.find()) {
matcher.appendReplacement(result, replacer.apply(matcher));
matcher.appendReplacement(result, Matcher.quoteReplacement(replacer.apply(matcher)));
}
matcher.appendTail(result);
result.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ class FieldTransformationsSpec extends AnyFlatSpec with Matchers with ProtocInvo
|import "google/protobuf/descriptor.proto";
|message FieldRules {
| optional Int32Rules int32 = 1;
| optional StringRules string = 2;
|}
|message Int32Rules {
| optional int32 gt = 1;
| optional int32 gte = 2;
| optional int32 lt = 3;
|}
|message StringRules {
| optional string const = 1;
|}
|extend google.protobuf.FieldOptions {
| optional FieldRules rules = 50001;
|};
Expand Down Expand Up @@ -432,6 +436,14 @@ class FieldTransformationsSpec extends AnyFlatSpec with Matchers with ProtocInvo
scalapbOptions("aux_field_options: { options: {type: \"Thingie(1)\"} }")
)

interpolateStrings(
fieldOptions("type: \"Thingie($([opts.rules].string.const))\""),
fieldRules("string: {const: \"r/(.{7}).*/$1xxxxx/\"}"),
extensions
) must be(
fieldOptions("type: \"Thingie(\"\"r/(.{7}).*/$1xxxxx/\"\")\"")
)

intercept[GeneratorException] {
interpolateStrings(
fieldOptions("type: \"Thingie($([opts.rules].int32.gtx))\""),
Expand Down

0 comments on commit 4003e62

Please sign in to comment.