[#5596] Error on code generation when schema name is a Windows reserved name like CON, AUX
This commit is contained in:
parent
a9f883a749
commit
994c94a43c
@ -191,6 +191,32 @@ class GenerationUtil {
|
||||
','
|
||||
)));
|
||||
|
||||
private static Set<String> WINDOWS_FORBIDDEN = unmodifiableSet(new HashSet<String>(asList(
|
||||
"CON",
|
||||
"PRN",
|
||||
"AUX",
|
||||
"CLOCK$",
|
||||
"NUL",
|
||||
"COM1",
|
||||
"COM2",
|
||||
"COM3",
|
||||
"COM4",
|
||||
"COM5",
|
||||
"COM6",
|
||||
"COM7",
|
||||
"COM8",
|
||||
"COM9",
|
||||
"LPT1",
|
||||
"LPT2",
|
||||
"LPT3",
|
||||
"LPT4",
|
||||
"LPT5",
|
||||
"LPT6",
|
||||
"LPT7",
|
||||
"LPT8",
|
||||
"LPT9"
|
||||
)));
|
||||
|
||||
/**
|
||||
* Take a character and determine if it's a valid "Scala Letter"
|
||||
* http://www.scala-lang.org/files/archive/spec/2.11/01-lexical-syntax.html
|
||||
@ -233,12 +259,25 @@ class GenerationUtil {
|
||||
* Letters, which include lower case letters (Ll), upper case letters (Lu), titlecase letters (Lt), other letters (Lo), letter numerals (Nl) and the two characters \u0024 ‘$’ and \u005F ‘_’, which both count as upper case letters.
|
||||
*
|
||||
* Character.isLetter handles the Ll, Lu, Lt, Lo, and Nl, supplement with _ and $
|
||||
*
|
||||
*/
|
||||
private static Boolean isScalaIdentifierPart(char c) {
|
||||
return isScalaIdentifierStart(c) || Character.isDigit(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a name and escape it if it is a Windows forbidden name like
|
||||
* <code>CON</code> or <code>AUX</code>.
|
||||
*
|
||||
* @see <a href="https://github.com/jOOQ/jOOQ/issues/5596">#5596</a>
|
||||
*/
|
||||
public static String escapeWindowsForbiddenNames(String name) {
|
||||
return name == null
|
||||
? null
|
||||
: WINDOWS_FORBIDDEN.contains(name.toUpperCase())
|
||||
? name + "_"
|
||||
: name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a literal (e.g. database column) and make it a Java identifier to be
|
||||
* used without case-change as an enum identifier
|
||||
|
||||
@ -41,6 +41,7 @@
|
||||
package org.jooq.util;
|
||||
|
||||
import static org.jooq.util.GenerationUtil.convertToIdentifier;
|
||||
import static org.jooq.util.GenerationUtil.escapeWindowsForbiddenNames;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
@ -322,6 +323,7 @@ class GeneratorStrategyWrapper extends AbstractGeneratorStrategy {
|
||||
className = delegate.getJavaClassName(definition, mode);
|
||||
className = overload(definition, mode, className);
|
||||
className = convertToIdentifier(className, language);
|
||||
className = escapeWindowsForbiddenNames(className);
|
||||
|
||||
return className;
|
||||
}
|
||||
@ -338,6 +340,7 @@ class GeneratorStrategyWrapper extends AbstractGeneratorStrategy {
|
||||
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
split[i] = convertToIdentifier(split[i], language);
|
||||
split[i] = escapeWindowsForbiddenNames(split[i]);
|
||||
}
|
||||
|
||||
return StringUtils.join(split, ".");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user