From f125acdde03fc249b4c8aed1cf545cfe565980f0 Mon Sep 17 00:00:00 2001 From: vam Date: Fri, 28 Jun 2019 16:01:47 -0700 Subject: [PATCH] Fix string literal character escaping in Ruby generator (seems like missing part in https://github.com/googleapis/gapic-generator/pull/2782) --- .../transformer/ruby/RubyModelTypeNameConverter.java | 3 ++- .../gapic/testdata/ruby/ruby_library.baseline | 12 ++++-------- .../protoannotations/testdata/ruby_library.baseline | 12 ++++-------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/google/api/codegen/transformer/ruby/RubyModelTypeNameConverter.java b/src/main/java/com/google/api/codegen/transformer/ruby/RubyModelTypeNameConverter.java index e466456646..bbf07a07df 100644 --- a/src/main/java/com/google/api/codegen/transformer/ruby/RubyModelTypeNameConverter.java +++ b/src/main/java/com/google/api/codegen/transformer/ruby/RubyModelTypeNameConverter.java @@ -16,6 +16,7 @@ import com.google.api.codegen.config.FieldConfig; import com.google.api.codegen.transformer.ModelTypeNameConverter; +import com.google.api.codegen.util.EscaperFactory; import com.google.api.codegen.util.NamePath; import com.google.api.codegen.util.TypeName; import com.google.api.codegen.util.TypeNameConverter; @@ -162,7 +163,7 @@ public String renderPrimitiveValue(TypeRef type, String value) { return value.toLowerCase(); case TYPE_STRING: case TYPE_BYTES: - return "\"" + value + "\""; + return "\"" + EscaperFactory.getDoubleQuoteEscaper().escape(value) + "\""; default: // Types that do not need to be modified (e.g. TYPE_INT32) are handled // here diff --git a/src/test/java/com/google/api/codegen/gapic/testdata/ruby/ruby_library.baseline b/src/test/java/com/google/api/codegen/gapic/testdata/ruby/ruby_library.baseline index ab3f0ce8c5..e98d4f1182 100644 --- a/src/test/java/com/google/api/codegen/gapic/testdata/ruby/ruby_library.baseline +++ b/src/test/java/com/google/api/codegen/gapic/testdata/ruby/ruby_library.baseline @@ -5707,8 +5707,7 @@ def sample_get_big_book shelf # Instantiate a client library_client = Library::Library.new version: :v1 - # shelf = "Novel\"` - # " + # shelf = "Novel\\\"`\b\t\n\r" formatted_name = library_client.class.book_path(shelf, "War and Peace") # Make the long-running operation request @@ -5746,8 +5745,7 @@ require "optparse" if $PROGRAM_NAME == __FILE__ - shelf = "Novel\"` - " + shelf = "Novel\\\"`\b\t\n\r" ARGV.options do |opts| opts.on("--shelf=val") { |val| shelf = val } @@ -6721,8 +6719,7 @@ def sample_get_big_book shelf # Instantiate a client library_client = Library::Library.new version: :v1 - # shelf = "Novel\"` - # " + # shelf = "Novel\\\"`\b\t\n\r" formatted_name = library_client.class.book_path(shelf, "War and Peace") # Make the long-running operation request @@ -6760,8 +6757,7 @@ require "optparse" if $PROGRAM_NAME == __FILE__ - shelf = "Novel\"` - " + shelf = "Novel\\\"`\b\t\n\r" ARGV.options do |opts| opts.on("--shelf=val") { |val| shelf = val } diff --git a/src/test/java/com/google/api/codegen/protoannotations/testdata/ruby_library.baseline b/src/test/java/com/google/api/codegen/protoannotations/testdata/ruby_library.baseline index d78b61fa74..1d0b70ebc2 100644 --- a/src/test/java/com/google/api/codegen/protoannotations/testdata/ruby_library.baseline +++ b/src/test/java/com/google/api/codegen/protoannotations/testdata/ruby_library.baseline @@ -5693,8 +5693,7 @@ def sample_get_big_book shelf # Instantiate a client library_client = Library::Library.new version: :v1 - # shelf = "Novel\"` - # " + # shelf = "Novel\\\"`\b\t\n\r" formatted_name = library_client.class.book_path("[BOOK_SHELF]", "[BOOK]") # Make the long-running operation request @@ -5732,8 +5731,7 @@ require "optparse" if $PROGRAM_NAME == __FILE__ - shelf = "Novel\"` - " + shelf = "Novel\\\"`\b\t\n\r" ARGV.options do |opts| opts.on("--shelf=val") { |val| shelf = val } @@ -6707,8 +6705,7 @@ def sample_get_big_book shelf # Instantiate a client library_client = Library::Library.new version: :v1 - # shelf = "Novel\"` - # " + # shelf = "Novel\\\"`\b\t\n\r" formatted_name = library_client.class.book_path("[BOOK_SHELF]", "[BOOK]") # Make the long-running operation request @@ -6746,8 +6743,7 @@ require "optparse" if $PROGRAM_NAME == __FILE__ - shelf = "Novel\"` - " + shelf = "Novel\\\"`\b\t\n\r" ARGV.options do |opts| opts.on("--shelf=val") { |val| shelf = val }