add function to handle missing delimiter in regex

This commit is contained in:
wing328
2016-08-22 18:01:06 +08:00
parent 44c8893ed5
commit a58845bb0f
11 changed files with 174 additions and 79 deletions

View File

@@ -542,7 +542,7 @@ public class DefaultCodegen {
* @return properly-escaped pattern
*/
public String toRegularExpression(String pattern) {
return escapeText(pattern);
return escapeText(addRegularExpressionDelimiter(pattern));
}
/**
@@ -3264,4 +3264,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");
}
}