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

fix expansion of strings containing references to capture groups #1038

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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