Merge pull request #3623 from wing328/ruby_better_pattern

Add function to handle missing delimiter in regex
This commit is contained in:
wing328
2016-08-22 19:12:03 +08:00
committed by GitHub
11 changed files with 174 additions and 79 deletions

View File

@@ -551,7 +551,7 @@ public class DefaultCodegen {
* @return properly-escaped pattern
*/
public String toRegularExpression(String pattern) {
return escapeText(pattern);
return escapeText(addRegularExpressionDelimiter(pattern));
}
/**
@@ -3273,4 +3273,19 @@ public class DefaultCodegen {
}
}
}
/**
* If the pattern misses the delimiter, add "/" to the beginning and end
* Otherwise, return the original pattern
*
* @param pattern the pattern (regular expression)
* @return the pattern with delimiter
*/
public String addRegularExpressionDelimiter(String pattern) {
if (pattern != null && !pattern.matches("^/.*")) {
return "/" + pattern + "/";
}
return pattern;
}
}

View File

@@ -727,4 +727,5 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
public String escapeUnsafeCharacters(String input) {
return input.replace("=end", "=_end").replace("=begin", "=_begin");
}
}