[Ruby] Escape string interpolation notation of Ruby (#2261) (#2287)

* escape string interpolation notation of Ruby (#2261)

* update samples (#2261)
This commit is contained in:
Akira Tanimura
2019-03-04 23:22:45 +09:00
committed by William Cheng
parent 88abea1755
commit 1d02f0374b
12 changed files with 82 additions and 22 deletions

View File

@@ -33,10 +33,10 @@ import java.util.Locale;
import static org.openapitools.codegen.utils.StringUtils.underscore;
abstract class AbstractRubyCodegen extends DefaultCodegen implements CodegenConfig {
abstract public class AbstractRubyCodegen extends DefaultCodegen implements CodegenConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractRubyCodegen.class);
AbstractRubyCodegen() {
public AbstractRubyCodegen() {
super();
setReservedWordsLowerCase(
@@ -177,7 +177,7 @@ abstract class AbstractRubyCodegen extends DefaultCodegen implements CodegenConf
@Override
public String escapeUnsafeCharacters(String input) {
return input.replace("=end", "=_end").replace("=begin", "=_begin");
return input.replace("=end", "=_end").replace("=begin", "=_begin").replace("#{", "\\#{");
}
@Override

View File

@@ -0,0 +1,26 @@
package org.openapitools.codegen.ruby;
import org.openapitools.codegen.languages.AbstractRubyCodegen;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
* Tests for AbstractRubyCodegen
*/
public class AbstractRubyCodegenTest {
private AbstractRubyCodegen codegen;
@BeforeMethod
public void setup() {
codegen = new AbstractRubyCodegen() {
};
}
@Test
public void testEscapeUnsafeCharacters() {
Assert.assertEquals(codegen.escapeUnsafeCharacters("=begin"), "=_begin");
Assert.assertEquals(codegen.escapeUnsafeCharacters("=end"), "=_end");
Assert.assertEquals(codegen.escapeUnsafeCharacters("#{x}"), "\\#{x}");
}
}